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 minimum and maximum length of an identifier?

6 Answers   TCS,


Why set do not allow duplicates in java?

0 Answers  


What are the methods to rectify ambiguities in the interfaces in JAVA?

0 Answers   CGI,


They had given one progam final HashMap hm=new HashMap(); public void show() { hm.put("name",value); } in this prg here the final hashtable value can be changed in put method,its the prg run?

3 Answers   DNS, Wipro,


suppose string s1="rajnish"; string s2="bhaskar"; then what will be happend ?

9 Answers   Fidelity,






Why main() method is public, static and void in java ?

0 Answers  


When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?

5 Answers   Ness Technologies,


Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?

0 Answers   Amazon,


What is a concrete classes? Is Java object class is concrete class?

0 Answers   Infosys,


Can you make a constructor final?

0 Answers  


How do you convert bytes to character in java?

0 Answers  


Explain the difference between a Thread and a Process.

0 Answers   Ciena,


Categories