title: Why this code doesn't call the subclass? Inheritance in Java
body: <pre><code>public class Parent {
      public  void printParent()
      {
          System.out.println("I am the Parent");
          System.out.println("----this is ::---" + this);
           this.printChild();
      }
      private void printChild()
      {
          System.out.println("This is my child");
      }
  }
  
  public class Child extends Parent {
      private void printChild()
      {
          System.out.println("I am the child");
      }
  }
  
  public class RelationshipTester {
      @Test
      public  void testRelation()
      {
          Child parent = new Child();
          parent.printParent();
      }
  }
  </code></pre>
  
  <p>This is the output :-</p>
  
  <p>I am the Parent</p>
  
  <p>----this is ::---datastructures.lists.inheritance.Child@1a692dec</p>
  
  <p>This is my child</p>
  
  <p>The object is of the type Child , yet it doesn't call the child method and the parent one. I have given this.printChild();</p>