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
What is a instance variable?
What are the types of exceptions?
What are keyboard events?
Explain about join() method?
What differences exist between iterator and listiterator?
What is java string pool?
Is it possible to compare various strings with the help of == operator?
give an example for encapsulation?
Which one of the following suits the description of a string better: derived or primitive?
How do generics work in java?
Can we cast any other type to boolean type with type casting?
Explain java code for recursive solution's base case?
how is final different from finally and finalize in java?
Explain treeset?
How to call one constructor from the other constructor ?