File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 9280

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
Similar Threads
Unreachable Code
InstanceOf Doubt.