SCJP Certification

Sun Certified Java Programmer Certification exam essentials

September 28th, 2011

What is runtime polymorphism or dynamic method dispatch?

Java Facts, by Daisy Williams.

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:

class Try {
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(); // call to the disp() method from Test.
}
}

Here, the Test version of the disp() method is called because the reference variable v of the type Try points to the Test object t1.

Share

Back Top

Responses to “What is runtime polymorphism or dynamic method dispatch?”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*