finding super class using reflection finding super class of a class in java finding super class of a class in java with example finding super class of a class in java using reflection how can we find a super class of a class using reflection finding super class of a class using reflection How to find Superclasses of a given class dynamically using Java Reflection API finding super class of a class in java dynamically using java reflection API can we find super class of a class dynamically finding super class using reflection with example program finding super class using reflection with example code
Finding Super Class of A Class:
1)
Whenever a class is loaded into A JVM along with
that class, it is super class is
also loaded into JVM.
2)
Whenever a class is loaded using forName method
then we will get a class object
by using it we can get a class object of its
super class by calling getSuperclass().
3) To get Name of class from class object, we call
getName().
Points To Remember:
1) In java a class can be public or default but a class cannot be private or protected.
2) Always public class name and program name should be same.
3) In java semicolon(;) is optional to terminate a class.
4) In JDK 1.5, we can write main method as main(String args[]) or main(String args).
5) In single java program, it is possible to make only one class as public. It means single java program does not contain multiple public classes in it.
The following application accepts
a class name as a command line argument prints its
super class name or
name of super class.
//ReflectDemo1.java
Class ReflectDemo1{
static public void main(String
args[]) {
Class
c=Class.forName(args[0]);
String s=s.getName();
Class sc=c.getName();
String s2=sc.getName();
System.out.println(s1+”extends”+s2);
}
}
Output :
C:\> javac ReflectDemo1.java
C:\> java ReflectDemo1 java.lang.Integer
Java.lang.Integer extends java.lang.Number
No comments:
Post a Comment