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 various access specifiers in java?
What is object of class in java?
Is array a class in java?
Can we declare main () method as non static?
What are the important features of Java 10 release?
Can we use a default constructor of a class even if an explicit constructor is defined?
What is the difference between an if statement and a switch statement?
Is arraylist zero based?
What is the protected method modifier?
How to make a write-only class in java?
What is unmodifiable collection in java?
which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com
What is the point of java?
What is difference between fileinputstream and filereader in java?
When do you get classcastexception?