File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Inheritance

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Source: http://www.go4java.20m.com/mock1.htm

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();
i.print();
}
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
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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: http://aspose.com/file-tools
 
subject: Inheritance
 
Similar Threads
Exception..
StringBuffer...
Unreachable Code
constructor..
InstanceOf Doubt.