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 does bitwise or mean?
Is an integer an object?
Can an abstract class be a final class?
How many ways can you break a singleton class in java?
Why char array is preferred over string for storing password?
what is the swingutilities.invokelater(runnable) method for? : Java thread
What is a char in java?
What is a for loop in java?
Why do we use regex?
What is difference between array and vector?
Why stringbuilder is not thread safe in java?
What is collections framework?
What is the collections api?
Is array serializable java?
Explain what access modifiers can be used for variables?