Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is dynamic method dispatch ?

Answer Posted / ankit

// Dynamic Method Dispatch

class A {

void callme() {

System.out.println("Inside A's callme method");

}

}

class B extends A {

// override callme()

void callme() {

System.out.println("Inside B's callme method");

}

}

class C extends A {

// override callme()

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

}

}



The output from the program is shown here:



Inside A's callme method

Inside B's callme method

Inside C's callme method



This program creates one superclass called A and two
subclasses of it, called B and C. Subclasses B and C
override callme( ) declared in A. Inside the main( ) method,
objects of type A, B, and C are declared. Also, a reference
of type A, called r, is declared.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is bytecode verifier?

992


What are the different conditional statements?

1049


Can we sort set in java?

1009


Can It is possible to synchronize the constructor of a Java Class?

1212


What is the default value of byte datatype in java?

974


How do you clear a method in java?

1048


Can a static member function access member variable of an object?

1055


What is locale?

1083


How does split work in java?

1102


How do you change an int to a string?

1059


How do you insert a line break?

960


What is the java reflection api? Why it’s so important to have?

1026


What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

1033


What is java Applet?

1153


What are different types of expressions?

1190