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?

Answers were Sorted based on User's Feedback



1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED..

Answer / vijay kumar

In case of dynamic method dispatch, It restricts from being used to call methods of other class. You cannot call overriden method which is not declared in reference variable class..
This is the main reason why we use reference variable here in dynamic polymorphism.

Hope i answer this question.

Is This Answer Correct ?    3 Yes 0 No

1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED..

Answer / 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

More Core Java Interview Questions

What access modifiers can be used for class ?

0 Answers  


What is meant by flickering?

0 Answers  


Give an example of call be reference significance.

0 Answers   Agilent,


What is the final field modifier?

0 Answers  


What is backdrop?

0 Answers   Atos Origin,


How do you identify if jvm is 32-bit or 64-bit from java program?

0 Answers  


What is data type example?

0 Answers  


What is final?

0 Answers  


Is a method a procedure?

0 Answers  


What is difference between null and void?

0 Answers  


What are the main features of java?

0 Answers  


What is class and its types?

0 Answers  


Categories