What is runtime polymorphism or dynamic method overloading?


Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Method overriding by a subclass is termed as runtime polymorphism. JVM determines the method to be executed at runtime instead of compile time. 

example

Live Demo

class SuperClass {
   SuperClass get(){
      System.out.println("SuperClass");
      return this;
   }
}
public class Tester extends SuperClass {
   Tester get(){
      System.out.println("SubClass");
      return this;
   }
   public static void main(String[] args) {
      SuperClass tester = new Tester();
 
      tester.get();
   }  
}

Output

SubClass

Updated on: 05-Mar-2020

969 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements