title: Java Inheritance classes with main method
body: <p>I have 2 objects defined</p>
  
  <p>In Object-1, When I reference the child object it invokes the child method m1() whereas in Object-2 when I reference the child method m1() it references the Parent object..</p>
  
  <p>In both the cases I assume parent object will hold a child type object at runtime...</p>
  
  <p>Object-1</p>
  
  <pre><code>    package pkgB;
  
      class Parent{
          static int i = 10;
          void m1(){
              System.out.println("In Parent = " + i);
          }
  
          static void m1(String s){
              System.out.println(s +i );
          }
      }
  
      public class Child extends Parent{
          static int i = 20;
          void m1(){
              System.out.println("In child" + Child.i);
          }
          public static void main(String[] args){
              Parent p = new Child();
              p.m1();
  
          }
      }
  </code></pre>
  
  <p>Object-2    </p>
  
  <pre><code>package pkgB;
  
  
  
  class Drink{
      public static void m1(){
          System.out.println("Im Drink method");
      }
  
  }
  
  class Coffee extends Drink{
      public static void m1(){
          System.out.println("Im Coffee method");
      }
  
  }
  
  public class test {
  
      public static void main(String[] args) {
          Drink d = new Coffee();
          d.m1();
  
      }
  }
  </code></pre>
  
  <p>Output Dobject-1:</p>
  
  <pre><code>In child20
  </code></pre>
  
  <p>Output Dobject-2:</p>
  
  <pre><code>Im Drink method
  </code></pre>