Access modifiers in java -
- protected and
Access specifier is synonymous of Access modifier. Please refer Java API doc
Diagram shows Access modifiers in java >
private, protected and public are Keywords in java language.
Tabular form to show where Access modifiers can be accessed in java >
In same class
Other classes of same package
classes of other packages
also known as default scope)
Yes, but only by inheritance, i.e. in subclasses.
Cannot be accessed by creating object of class.
Access modifiers during method overriding >
when overriding method of subclass Must not have more restrictive access modifier.
- private can be accessed only within the same class.
- Default can be accessed only within the classes of same package.
- Protected can be accessed within the classes of same package and in classes of other packages only by inheritance, i.e. in subclasses.
- Public are accessible from everywhere.
/** JavaMadeSoEasy.com */
Labels: Core Java