What is runtime polymorphism or dynamic method dispatch?
What is runtime polymorphism or dynamic method dispatch?
Rating:
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. For example:
void disp() {}
}
class Test extends Try {
void disp() {}
public static void main(String args[]){
Try t=new Try();
Test t1=new Test();
Try v;
v=t1;
v.disp();
}
Here, the Test version of the disp() method is called because the reference variable r of the type Try points to the Test object t1.
Rating:
Other articles
- What is NoClassDefFoundError?
- What is the && operator?
- New features in Java certification exam.
- What is the Set interface?
- What is Swing?
