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 the default execution method in java?

0 Answers  


What is a string token?

0 Answers  


What method is used to know the status of Checkbox(i.e it is checked or unchecked)?

1 Answers  


i would like to attend for an interview of datalab technologies company i want to know the pattern of imnterview.

0 Answers  


33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(”a”); 37. } catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34? 1 c 2 a 3 ab 4 ac

5 Answers  






What is the right data type to represent a price in java?

0 Answers  


What is java command?

0 Answers  


How many ways can we create singleton class?

0 Answers  


what is difference between colection and collections?

25 Answers   Amdocs, IBM, Infosys, Ipog Software, Polaris, Tech Mahindra,


What is finalize()?

0 Answers  


Why cant we define System.out.println() inside a class directly?

5 Answers  


What's the base class of all exception classes?

0 Answers  


Categories