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

when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service

4 Answers   Accenture,


what is the difference between equals method and ==

17 Answers   IBM, Professional Access, TCS,


What is Yield() method when we r using this ? tell exactly

2 Answers  


What do u mean by method and also contructer in java ?

3 Answers  


What is boolean flag in java?

0 Answers  






when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???

0 Answers   SAP Labs,


what is java

10 Answers  


What is the use of inner class?

0 Answers  


What is int argc char * argv?

0 Answers  


Who developed JScript language?

3 Answers  


What is the difference between abstract classes and interfaces?

0 Answers  


What is difference between equal and == in java?

0 Answers  


Categories