Get parent class for a method in Java
Description
The following code shows how to get parent class for a method.
Example
/* w w w . j a v a 2 s.c o m*/
import java.lang.reflect.Method;
public class Main {
public static void main(final String[] args) {
Method[] methods = String.class.getMethods();
for (int idx = 0; idx < methods.length; idx++) {
System.out.println(methods[idx] + " declared by "
+ methods[idx].getDeclaringClass());
}
}
}
The code above generates the following result.