Friday, June 26, 2009

Controlling Access to Class Members

The options you have for specifying the accessibility of a variable or a method in a class are:
AttributePermitted Access
No access attributeFrom methods in any class in the same package
publicFrom methods in any class anywhere as long as the class has been declared as public
privateAccessible only from methods inside the class. No access from outside the class at all.
protectedFrom methods in any class in the same package and from any subclass anywhere.
This may sound more complicated than it actually is. The following image shows the access allowed between classes within the same package.



The next image shows the access allowed between classes in different packages.

No comments:

Post a Comment