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 is the similarity between dynamic binding and linking?
Can we convert stringbuilder to string in java?
What is the difference between jvm and jre? What is an interface?
Can a class have multiple subclasses?
Does java list allow null?
What is the main advantage of passing argument by reference?
Do you know why doesn't the java library use a randomized version of quicksort?
Difference between throw and throws?
Why are data types important?
What is the difference between object oriented programming language and object based programming language?
How many bytes is 255 characters?
Can we assign null to double in java?
What is the difference between a constructor and a method?
What is the size of integer?
How do you reverse a string in java without using string buffer?