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...

1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE
VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO
ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT
RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE
VARIABLE" HERE?

Answer Posted / shweta kunjadia

It shows Runtime Polymorphism

Eg.

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
}
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

959


Explain the significance of listiterator.

1023


What is the final blank variable?

1069


Difference between start() and run() method of thread class?

996


What is an example of a constant variable?

1008


What is identifier in java?

1024


What does n mean in java?

923


Can an unreferenced object be referenced again?

1136


What is the purpose of stub and skeleton?

955


What is default switch case? Give example.

951


What is fail fast in java?

1059


What do you understand by copy constructor in java?

880


What are the differences between string and stringbuffer?

1057


Can a class extend more than one class?

1052


What is the properties class?

1031