title: Method overriding and Inheritance in java
body: <p>Consider the following code segment:</p>
  
  <pre><code>class A{ /* assume static and non static block are here */ }
  class B extends A{ /* assume static and non static block are here */ }
  </code></pre>
  
  <p>In main method,</p>
  
  <pre><code> new B();
  </code></pre>
  
  <p>So the order of the initialization would be :</p>
  
  <ol>
  <li>static members initialization for class A</li>
  <li>static members initialization for class B</li>
  <li>non static members initialization for class A</li>
  <li>then execute the code inside constructor A</li>
  <li>non static members initialization for class B</li>
  <li>then execute the code inside constructor B</li>
  </ol>
  
  <p>Now take a look at this code segment,</p>
  
  <pre><code>class A{
      A(){
          this.m(); //line 1
      }
  
      void m(){
          System.out.println("A.m()");
      }
    }
  
    class B extends A{
       void m(){
          System.out.println("B.m()");
      }
    }
  </code></pre>
  
  <p>In main method,</p>
  
  <pre><code> new B();
  </code></pre>
  
  <p>When the code of constructor A is being executed, it can only see the method m in class A since non static members hasn't been initialized yet for class B (according to the order I mentioned).
  However the result is "B.m()". (method of sub class has been executed)
  Can someone explain what is happening here(method overridng) considering the order that I have mentioned ?</p>