title: Getting Declared Methods - Java
body: <p>Suppose I have the following three classes</p>
  
  <p><strong>A.java</strong></p>
  
  <pre><code>public class A {
      public static void main (String[] args) {
          new C();
      }
  }
  </code></pre>
  
  <p><strong>B.java</strong></p>
  
  <pre><code>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() {
  
      }
  }
  </code></pre>
  
  <p><strong>C.java</strong></p>
  
  <pre><code>public class C extends B{
      public C() {
          super();
      }
  }
  </code></pre>
  
  <p>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 <code>[]</code>. This is a surprise to me, as I was expecting the output to be (assuming all classes are in package called <code>test</code>):</p>
  
  <pre><code>[public void test.B.hello()]
  </code></pre>
  
  <p>So, what's wrong? And how do I get it so that this is the actual output?</p>