title: In Java Invoking a method using Reflection is not able to find method, when method has baseclass as parameter
body: <p>Below is the code snippet, I am trying to invoke the <code>usingClass</code> method using REFLECTION. Calling the <code>usingClass()</code> method directly(w/o reflection) works when I pass an object of type Child, though when I try to achieve the same thing using Reflection it throws <code>NoSuchMethodFoundException</code>. Would like to understand if I am missing something or is there any logic behind this? Please help</p>
  
  <pre><code>package Reflection;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  public class TestMethodInvocation {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          TestMethodInvocation test = new TestMethodInvocation();
          Child child = new Child();
          Parent parent = (Parent)child;
          Class&lt;? extends Parent&gt; argClassType = parent.getClass();
          Class&lt;? extends TestMethodInvocation&gt;  thisClassType = test.getClass();
  
          test.usingClass(child);
  
          Method methodToCall;
          try {
              methodToCall = thisClassType.getDeclaredMethod("usingClass", argClassType);
              methodToCall.invoke(test, parent);
          } catch (SecurityException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (NoSuchMethodException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IllegalArgumentException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (InvocationTargetException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      private void usingClass(Parent p){
          System.out.println("UsingClass: " + p.getClass());
      }
  
  
  }
  </code></pre>
  
  <p><strong>Output is as below.</strong></p>
  
  <pre><code>UsingClass: class Reflection.Child
  java.lang.NoSuchMethodException: Reflection.TestMethodInvocation.usingClass(Reflection.Child)
      at java.lang.Class.getDeclaredMethod(Unknown Source)
      at Reflection.TestMethodInvocation.main(TestMethodInvocation.java:20)
  </code></pre>