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 is the similarity between dynamic binding and linking?

1067


Can we convert stringbuilder to string in java?

943


What is the difference between jvm and jre? What is an interface?

1023


Can a class have multiple subclasses?

1059


Does java list allow null?

929


What is the main advantage of passing argument by reference?

917


Do you know why doesn't the java library use a randomized version of quicksort?

913


Difference between throw and throws?

1055


Why are data types important?

1007


What is the difference between object oriented programming language and object based programming language?

953


How many bytes is 255 characters?

930


Can we assign null to double in java?

966


What is the difference between a constructor and a method?

1170


What is the size of integer?

1056


How do you reverse a string in java without using string buffer?

1050