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
Are generics important java?
Which is better 64 bit or 32 bit?
What is lazy initialization in java?
What is core java used for?
Can singleton class be inherited in java?
What does || || mean in math?
What does a boolean method return?
Is void a keyword in java?
What is array in java?
What is formatted output in java?
What is the generic class?
What is a programming object?
What are keywords in programming?
What is parsing a string?
What is boolean in java?