This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes default members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "default members" Watch "default members" New topic
Author

default members

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
K&B page 82
Just remember that default members are visible only to the subclasses that are in the same package as the superclass.


Does that mean class that are in the same package but not subclasses cannot access default memebers.
I tried the following code and it works




Am i interpreting it incorrectly?
ananda s. roy
Greenhorn

Joined: May 13, 2004
Posts: 12
Hi
When u compile the program 2 classes Parent & Child are created in the directory where the source file is i.e in the default package.Just think package as a directory under which several classes exists. So Child class access the Parent object thru AGGREGATION.
Hope u have got it.


SCJP 1.4
Jong Limb
Greenhorn

Joined: May 08, 2004
Posts: 12
Originally posted by Angela lewis:
K&B page 82
Just remember that default members are visible only to the subclasses that are in the same package as the superclass.

Does that mean class that are in the same package but not subclasses
cannot access default memebers.
I tried the following code and it works




Am i interpreting it incorrectly?



There are two questions involved here. One is the package location of a subclass in relation to its superclass. For this point, default members are not accessible when the subclass is in a different package than the superclass. Protected members, in contrast, *are* accessible to subclasses regardless which package the subclass is in.

The second question is the accessibility of default members for classes in the same package that aren't subclasses. Any class in the same package can access default members. That is why your example works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default members
 
Similar Threads
Not convinced with K&B solution for couple of questions, please help
Referencing a Parent variable from a Child subclass in a different package
problem on extending a class declared on the same package!!
accessing protected members
default vs protected access