• Post Reply Bookmark Topic Watch Topic
  • New Topic

access level for members of a package-level access class  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Given a class that is defined with package-level access (non-public), why would you ever define any of its members with public access?

As I understand it, the class is only visible to other classes in the same package, so the members of the class would not be visible outside the package either.

Also, can package-level access members of the class be inherited by subclasses defined in the same package?

Thank you,
R. Warren
 
Marshal
Posts: 56603
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, default access members are inherited by subclasses.
You can have a subclass which overrides a default access method with public or protected access. You can subclass a class by a public class, when its public members become visible outwith the package, so yes, it may be worthwhile having public access methods.

Obviously you will keep all non‑constant fields private.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!