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 are the various access specifiers in java?

569


What is object of class in java?

599


Is array a class in java?

505


Can we declare main () method as non static?

524


What are the important features of Java 10 release?

511






Can we use a default constructor of a class even if an explicit constructor is defined?

656


What is the difference between an if statement and a switch statement?

650


Is arraylist zero based?

559


What is the protected method modifier?

563


How to make a write-only class in java?

579


What is unmodifiable collection in java?

514


which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com

3193


What is the point of java?

554


What is difference between fileinputstream and filereader in java?

562


When do you get classcastexception?

558