title: When child class Instance becomes Parent class Instance
body: <p>I'm trying to understand how child class's instance becomes parent's class instance. I mean what kind of model they get in memory once created.</p>
  
  <p>Check below code snippet</p>
  
  <pre><code>public class Parent {
      public String log4jConfig;
  
      public void setLog4jConfig(String log4jConfig){
          System.out.println(this.getClass());  ---4
          this.log4jConfig = log4jConfig;
      }
  
      public String getLog4jConfig() {
          return log4jConfig;
      }
  }
  
  public class Child extends Parent {
  }
  
  public class Mainclass {
      public static void main(String[] args) {
          Child obj = new Child(); // ---1
          obj.setLog4jConfig("log4jConfig");
      }
  }
  </code></pre>
  
  <p>When I create an instance of child class, It can access all methods of parent's class because those are inherited. </p>
  
  <p>And <code>this</code> represents the current class Instance, So why am getting at 4 Child's class name ? So if CHILD IS PARENT when extended then how it sits in memory, I'm trying to visualize the sitting plan of Parent and child class in memory where <code>this</code> of parent becomes Child's instance. </p>
  
  <p>OR When extended, Does it creates a two copies of Methods for respective parent and child classes which are inherited in memory ?</p>
  
  <p>Any Help Please..!</p>
  
  <p>Thanks</p>