

Hi,
Here is the answer.
In Java, 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.
Example-
class Test {
void show() {
System.out.println("A Beautiful flower.");
}
}
class Rose extends Test {
void show() {
System.out.println("pink");
}
}
class Lotus extends Test {
void show() {
System.out.println("rose.");
}
}
public class RunTime {
public static void main(String[] args) {
Test ref1 = new Test();
Test ref2 = new Rose();
Test ref3 = new Lotus();
ref1.show();
ref2.show();
ref3.show();
}
}
Output-
A Beautiful flower. pink rose.
Thanks.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.