0 votes
in JAVA by
What is Runtime Polymorphism?

1 Answer

0 votes
by

Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

class Bike{  

  void run(){System.out.println("running");}  

}  

class Splendor extends Bike{  

  void run(){System.out.println("I am running safely with 60km");}  

  public static void main(String args[]){  

    Bike b = new Splendor();//upcasting  

    b.run();  

  }  

}  

Test it Now

Output:

I am running safely with 60km.

In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

Related questions

0 votes
asked Jan 24, 2021 in JAVA by rajeshsharma
+1 vote
asked Jan 10, 2021 in JAVA by rajeshsharma
...