Controlling Access to Members of a Class
by, 04-26-2012 at 05:43 PM (506 Views)
It is determined by the Access level modifier that a particular field or method could be used or invoked by the other classes or not. Access control levels are as following:
- At the top level, which is package-private or private i.e no explicit modifier.
- At the member level, this is public, protected, private or package-private i.e. no explicit modifier.
With modifier public, declaration of the class might be done. In that case class becomes visible to classes, everywhere. If no modifier (also named as package private) is present in a class then it’s just visible in its own package.
No modifier or public modifier could also be used at the member level just like it is done at top leveled class. Additional access modifiers are present for the members, which are “protected” & “private”. It is been specified by the private modifiers that members could just be accesses in their class. It is been specified by the protected modifiers that members could be accessed just in their package and also by the class’s subclass which is present in some other package.