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

In Inheritance if we are implementing Multi level inheritance
and all class having same name of variable and now i want to
access each class variable and how it is possible?

Answer Posted / megha

IF ClassC extends ClassB and ClassB extends ClassA
All Classes having "public int a " with different values,
then
ClassA objA = new ClassA();
ClassB objAB = new ClassB();
ClassC objAC = new ClassC();

System.out.println(objA.a);
System.out.println(objAB.a);
System.out.println(objAC.a);
will show each class variable individually

****************************O R *******************

make a method to return superclass variable using "super.a"

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does the three dot emoji mean?

1124


What is entry set in java?

1140


What is the syntax and characteristics of a lambda expression?

1045


What is the difference between variable declaration and variable initialization?

1030


What is class forname?

1022


What is a variable and constant?

1003


What is the benefit of inner / nested classes ?

988


Is a string literal?

1097


What is difference between variable declaration and definition?

970


What is a boolean expression in java?

1022


What is treemap in java?

944


Can inner class be public in java?

1015


why not override thread to make a runnable? : Java thread

1005


What is data type in java?

904


What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

1132