Answer Posted / manishsoni
class A
{
void callme()
{
System.out.println("Inside A's callme method");
}
}
class B extends A
{
void callme()
{
System.out.println("Inside B's callme method");
}
}
class C extends A
{
void callme()
{
System.out.println("Inside C's callme method");
}
}
class Dispatch
{
public static void main(String args[])
{
A a = new A(); // object of type A
B b = new B(); // object of type B
C c = new C(); // object of type C
A r; // obtain a reference of type A
r = a; // r refers to an A object
r.callme(); // calls A's version of callme
r = b; // r refers to a B object
r.callme(); // calls B's version of callme
r = c; // r refers to a C object
r.callme(); // calls C's version of callme
}
}
MoNu
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
If an object is garbage collected, can it become reachable again?
What is singleton math?
What is the file type?
What happens when I use / and % with a negative numerator?
Is void a keyword in java?
What is difference between identifier and variable?
How to create a thread in java?
What is an immutable object?
Program to Find the second largest element in an array.
How do you declare a variable?
What is an example of a keyword?
Is oracle java 11 free?
What do you mean by local variable and instance variable?
What is the memory leak in java?
extending thread class or implementing runnable interface. Which is better? : Java thread