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
How java enabled high performance?
What are desktop procedures?
What is the difference between normal report & matrix report?
What is a java applet? What is an interface?
how to create multithreaded program? : Java thread
What is difference between final and finally in java?
How does linkedhashmap work in java?
What are the rules for variable declaration?
Is finalize() similar to a destructor?
How can we make copy of a java object?
How can we run a java program without making any object?
Can we have a method name same as class name in java?
What does string intern() method do?
What are 4 pillers of object orinted programming?
Can constructor be static or final?