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
Is upper case in java?
What is a protected method?
explain autoboxing in java?
define polymorphism in java
Can a set contain duplicates?
What is difference between overloading and overriding in java?
How will you call an Applet using Java Script Function?
What is size_t?
What is replaceall in java?
What is static import in java?
Why volatile is used in java?
what is the constructor and how many types of constructors are used in java?
What is java ceil?
Can I uninstall java?
What is meant by method?