Topic:   Runtime Polymorphism?
Apr 19, 2021 11:43 1 Replies 80 Views ROHAN

What is Runtime Polymorphism?

Prev Next
Topic Replies (1)
  1. 1
    idnkx user

    VAMSI

    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.
    1. class Bike{
    2. void run(){System.out.println("running");}
    3. }
    4. class Splendor extends Bike{
    5. void run(){System.out.println("running safely with 60km");}
    6. public static void main(String args[]){
    7. Bike b = new Splendor();//upcasting
    8. b.run();
    9. }
    10. }

    OUTPUT:
    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.

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect