Member’s Access Modifiers
Below is a summary of the principle characteristic of the access and non-access modifiers used in class declarations.
public
- All classes regardless of package can access the member.
private:
- Can only be accessed from within own class.
- A private member is invisible to any code outside its own class.
- A subclass cannot inherit a private member.
- You can declare a member of the same name in a subclass but it is not overridden.
- You can only override methods that can be inherited.
package default:
- Can be accessed by classes of the same package.
- Becomes private to classes in other packages.
protected:
- Accessed by same package and by subclasses in other packages.
- Respects the inheritance concept.
- The inherited protected member becomes private to all other classes in the subclasses package.
Leave a Reply