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 does the three dot emoji mean?
What is entry set in java?
What is the syntax and characteristics of a lambda expression?
What is the difference between variable declaration and variable initialization?
What is class forname?
What is a variable and constant?
What is the benefit of inner / nested classes ?
Is a string literal?
What is difference between variable declaration and definition?
What is a boolean expression in java?
What is treemap in java?
Can inner class be public in java?
why not override thread to make a runnable? : Java thread
What is data type in java?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?