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 principle concepts of oops?

751


How do you reverse sort in java?

739


What is += mean in java?

788


Can inner class final?

888


What is the difference between dom and sax parser in java?

779


Is multiple inheritance supported by java?

716


What is a parameter in java?

756


What are the loops in java?

771


What are the new features in java 8?

822


Define max and min heap, also the search time of heap.

842


Can we sort hashset in java?

875


what is difference between equals and ==?

822


What do you mean by inner class in java? Explain

829


What is a values collection view ?

887


Does substring create a new object?

775