title: Example of Runtime polymorphism in Java?
body: <p>How is Runtime polymorphism different from Static polymorphism ?</p>
  
  <p>Can this be an example of Runtime polymorphism ?</p>
  
  <pre><code>public class X
  {
      public void methodA() // Base class method
      {
          System.out.println ("hello, I'm methodA of class X");
      }
  }
  
  public class Y extends X
  {
      public void methodA() // Derived Class method
      {
          System.out.println ("hello, I'm methodA of class Y");
      }
  }
  public class Z
  {
     public static void main (String args []) {
         X obj1 = new X(); // Reference and object X
         X obj2 = new Y(); // X reference but Y object
         obj1.methodA();
         obj2.methodA();
     }
  }
  </code></pre>
  
  <p>The code has been picked from <a href="http://beginnersbook.com/2013/04/runtime-compile-time-polymorphism/" rel="nofollow noreferrer">here</a> </p>