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
How does queue work in java?
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
How listener identify that the event came from a particular object?
What is static in java?
What do you mean by local class?
Is the milky way in a void?
What is double checked locking in singleton?
What is the generic function?
What is int short for?
What is the difference between a choice and a list?
Which is better stringbuilder or stringbuffer?
What is skeleton and stub?
Can you achieve runtime polymorphism by data members?
What is final int?
What is the current version of java?