Pages

Get all interface from a class object

This program will print name of interface that implemented by this class

**********************************************************
COMPLETE SOURCE CODE FOR : ListingAllInterfaceFromClassObject.java
**********************************************************


import java.awt.event.ActionListener;//INTERFACE 1
//Runnable-INTERFACE 2
import java.awt.event.ActionEvent;

public class ListingAllInterfaceFromClassObject implements ActionListener,Runnable
{
public void actionPerformed(ActionEvent evt)
{
//NO IMPLEMENTATION
}

public void run()
{
//NO IMPLEMENTATION
}

public static void main(String[]args)
{
try
{
Class temp=Class.forName("ListingAllInterfaceFromClassObject");
Class[]allInterface=temp.getInterfaces();
int allInterfaceLength=allInterface.length;
int temp2=0;
while(temp2!=allInterfaceLength)
{
System.out.println("INTERFACE "+(temp2+1)+" :"+(allInterface[temp2].getSimpleName()));
temp2=temp2+1;
}
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


**********************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************
Related Posts Plugin for WordPress, Blogger...