Reflection
Reflection is used to in java to obtain run-time information about class or method.
With reflection we can find
· Number of instance methods.
· Number of static methods.
· Determining modifiers of the class.
etc.
Inorder to use reflection we must import java.lang.reflect.* pacackage.
class ReflectionTesting
{
public static void main (String [] args)
{
String s=new String ("Hello Reflection");
printParentclass (s);
}
static void printParentclass (Object s)
{
Class c=s.getClass ();
Class sc=c.getSuperclass ();
System.out.println ("NAME OF this CLASS : "+c.getName ());
System.out.println ("NAME OF parent CLASS : "+sc.getName ());
}
};
Reflection is used to in java to obtain run-time information about class or method.
With reflection we can find
· Number of instance methods.
· Number of static methods.
· Determining modifiers of the class.
etc.
Inorder to use reflection we must import java.lang.reflect.* pacackage.
class ReflectionTesting
{
public static void main (String [] args)
{
String s=new String ("Hello Reflection");
printParentclass (s);
}
static void printParentclass (Object s)
{
Class c=s.getClass ();
Class sc=c.getSuperclass ();
System.out.println ("NAME OF this CLASS : "+c.getName ());
System.out.println ("NAME OF parent CLASS : "+sc.getName ());
}
};
Comments
Post a Comment