"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
protected: if a member is protected, it's accessible to all classes in the same package (doesn't matter of it is a subclass or not)
Originally posted by Thomas Drew:
Roel this is wrong.
for a class to access a protected member of another class it has to be a child of that class. Even if two class are in the same package, if class B isn't inherited from class A class B will not be able to access any protected members of class A.
Thanks & Regards<br /> <br />-Srikanth
SCJP 1.4
Originally posted by Sandeep Narasimhamurthy:
Hi,
You are all messed up.
Any class within the same package can access protected members (variables/methods).
Sub class or not, doesn't matter. It can access protected members.
Then what's the use of protected ?
---------------------------------
Protected comes into picture for classes in OTHER PACKAGE.
If there is a subclass in other package, it can access Protected members. Not directly, buy by declaring objects of subclass, it can access protected members of parent class.
This mechanism provides a way to access protected members from other packages. Without this, only PUBLIC members will be available to classes of other packages, inherited or not.
Thanks & Regards<br /> <br />-Srikanth
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP 5, SCWCD 1.4, SCBCD 5
Thanks & Regards<br /> <br />-Srikanth