Suppose I have the following three classes
A.java
public class A {
public static void main (String[] args) {
new C();
}
}
B.java
import java.lang.reflect.Method;
import java.util.Arrays;
public class B {
public B() {
Method[] m = this.getClass().getDeclaredMethods();
System.out.println(Arrays.toString(m));
}
public void hello() {
}
}
C.java
public class C extends B{
public C() {
super();
}
}
and I run the main method in class A. Well, it should instantiate class C, which in turn should call class B's constructor, to print out the declared methods. The output is []. This is a surprise to me, as I was expecting the output to be (assuming all classes are in package called test):
[public void test.B.hello()]
So, what's wrong? And how do I get it so that this is the actual output?
thisis an instance of C.B.class.getDeclaredMethods()B.class.getDeclaredMethods()