what is dynamic method dispatch ?

Answer Posted / salman

In dynamic method dispatch,super class refers to subclass object and implements method overriding.
Example:

class Flower {
void which() {
System.out.println("A Beautiful flower.");
}
}
class Rose extends Flower {
void which() {
System.out.println("Rose");
}
}
class Lotus extends Flower {
void which() {
System.out.println("Lotus.");
}
}
class Test {

public static void main(String[] args) {
Flower ref1 = new Flower();
Flower ref2 = new Rose();
Flower ref3 = new Lotus();
ref1.which();
ref2.which();
ref3.which();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is upper case in java?

525


What is a protected method?

591


explain autoboxing in java?

591


define polymorphism in java

628


Can a set contain duplicates?

515






What is difference between overloading and overriding in java?

525


How will you call an Applet using Java Script Function?

540


What is size_t?

499


What is replaceall in java?

541


What is static import in java?

526


Why volatile is used in java?

526


what is the constructor and how many types of constructors are used in java?

531


What is java ceil?

566


Can I uninstall java?

548


What is meant by method?

575