What is dynamic dispatch in java?

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


Please Help Members By Posting Answers For Below Questions

Wha is the output from system.out.println(“hello”+null); ?

691


What is the maximum size of array in java?

518


Explain the difference between protected and default access.

514


Why is the type for real numbers called double?

545


How define set in java?

514






What is the constructor?

581


What do you mean by hashing?

645


Explain throw keyword in java?

611


What is number data type?

532


What is the size of boolean variable?

575


Write an algorithm program in java for the following question.. 1) S is a set of integers.X is an integer obtained by sum of two digits in S. Write logic for whether or not the X is from the S. The time of algorithm should not exceed o(n logn).

1605


Can abstract class have private constructor?

498


What are synchronized methods ?

617


How do you add an element to a hashset in java?

492


What is outofmemoryerror in java?

568