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 is treeset implemented in java?
Explain about automatic type conversion in java?
Why declare Main() inside the class in java ?
Can an interface have a constructor?
What is generic type?
What is parsing and its types?
How would you dynamically allocate memory to an array?
Which number is denoted by leading 0x or 0x in java?
What are predefined functions?
What is lambda in java?
Which container method is used to cause a container to be laid out and redisplayed in java programming?
Is arraylist ordered in java?
What is role of void keyword in declaring functions?
In java, what is the difference between method overloading and method overriding?
What is the different between get and post?