This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance" Watch "Inheritance" New topic


Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509

class Message
String text="Hello1";
class Super
Message msg=new Message();
class inheritance extends Super
public static void main(String arg[])
inheritance i=new inheritance();
public void print()
System.out.println(super.msg.text);// Prints Hello1.

Here msg.txt as well as super.msg.text prints the same ouput, how is that possible?
Ankit Garg

Joined: Aug 03, 2008
Posts: 9293

it is possible because super.msg and msg point to the same object. Since there is not object in Inheritance class with the name msg, so both the syntax will point to the same object...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Inheritance