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
What are the principle concepts of oops?
How do you reverse sort in java?
What is += mean in java?
Can inner class final?
What is the difference between dom and sax parser in java?
Is multiple inheritance supported by java?
What is a parameter in java?
What are the loops in java?
What are the new features in java 8?
Define max and min heap, also the search time of heap.
Can we sort hashset in java?
what is difference between equals and ==?
What do you mean by inner class in java? Explain
What is a values collection view ?
Does substring create a new object?