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?

Answers were Sorted based on User's Feedback



In Inheritance if we are implementing Multi level inheritance and all class having same name of va..

Answer / 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

In Inheritance if we are implementing Multi level inheritance and all class having same name of va..

Answer / sabari

We cannot use the same name for all classes.

Is This Answer Correct ?    7 Yes 11 No

Post New Answer

More Core Java Interview Questions

What is string builder in java?

0 Answers  


What is compareto () in java?

0 Answers  


Explain parallel processing in java8?

0 Answers  


What is the format specifier?

0 Answers  


Name the packages in JDK?

2 Answers  


What do you understand by abstract classes?

0 Answers   HCL,


What will happen when using pass by reference in java?

0 Answers   HCL,


Which methods are used during serialization and deserialization process?

0 Answers  


The class "Class" is belongs to which package?? a) java.lang b)java.lang.reflect c)java.util d)None

4 Answers  


What do you understand by the term polymorphism?

0 Answers  


What is contractor means and methods?

0 Answers  


What do you know about the garbage collector?

0 Answers  


Categories