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

In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?

1096


Is java a utf 8 string?

748


What is the size of integer?

832


What is an off by one error in java?

722


Why java is secure? Explain.

778


Why is string buffer better than string ?

800


What does you mean in math?

775


What is use of static method?

764


Explain about narrowing conversion in java?

775


Name container classes in java programming?

805


What is the range of the short type?

785


What is constructor and its types?

790


What is boolean flag in java?

800


How many types of parsers are there?

786


What do you understand by java?

756