• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

default members

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic