This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance" Watch "Inheritance" New topic


M Rama
Ranch Hand

Joined: Mar 04, 2005
Posts: 91


Parent Class
Parent Class


Child Class
Child Class

I understand the static method printing. But not the instance variable str.

Is this material covered in K&B( Chapter 5 doesn't have it and I am yet to read 3 and 6 from first 9 )? Is there a different book I need to read for this?
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Static methods are cannot be overriden. So it is execute current class methods like print(). Once again I noticed, Instance members are cannot be overriden. It is hiding. In Overriding Methods are executed based on the Object reference. But memebers variables ae accessed based on class. ie., classname.variable. If u have any more doubts walk through the code available in your previous posting

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
Sakthi Kani
Ranch Hand

Joined: Mar 29, 2005
Posts: 98
hai rama,
as far as ur program is concerned,u r trying to access a static method.
in general,static methods take the reference and not objects & so u get the result (as mentioned in ur 1st code).


I understand the static method printing. But not the instance variable str.


instance variables are similar in behaviour to static methods,they too refer only the reference and not the objects.
hence according to ur code(both 1st & 2nd ),u r creating the reference for the class & trying to print the str(instance variable)from that class,since instance variables refer to references & not objects,it takes the value os str in that particular class which it refers to.

if still not clear,plz reply


" Don't be afraid of pressure. Remember that pressure is what turns a lump of coal into a diamond... " <br /> <br />Thanks & Regards...<br />Sakthi<br />SCJP1.4, OCA
I agree. Here's the link:
subject: Inheritance
It's not a secret anymore!