Java Reflection
Java Reflection
import java.lang.Class;
import java.lang.reflect.*;
class Animal {
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Output
Name: Dog
Modifier: public
Superclass: Animal
For example,
Method class - provides information about methods in
a class
Field(Data members) class - provides information
about fields in a class
Constructor class - provides information about
constructors in a class.
Reflection of Java Methods
The Method class provides various methods that can
be used to get information about the methods present
in a class.
For example,
import java.lang.Class;
import java.lang.reflect.*;
class Dog {
class Main {
public static void main(String[] args) {
try {
// create an object of Dog
Dog d1 = new Dog();