2. DEFINATION OF ACCESS MODIFIER
• It is simply a keyword in java that provides accessibility of a class and its members.
• Set in the access level to method, variable, classes and constructors.
• Classification of access modifier are:-
• Private
• Protected
• Public
3. PRIVATE ACCESS MODIFIER
• It is the most restrictive access level whereby they are accessible only within the class itself.
• A superclass private members are not inherited by its subclasses.
• Example of Private Access Modifier is:
4.
5. PROTECTED ACCESS MODIFIER
• It can be accessed by only the class of same package and the subclass present in any package.
• It has visibility in sub classes and Classes cannot be declared as protected.
• Example of Protected Access Modifier:
6.
7. PUBLIC ACCESS MODIFIER
• It can be access with any classes.
• It is widest scope among all other modifiers.
• Example of Public Access Modifier is:
8.
9. SCOPE OF ACCESS MODIFIERS IN TABULAR FORM
Access
Modifier
Within
Class
Within
Package
Outside Package By
Subclass only
Outside
Package
Private Y N N N
Protected Y Y Y N
Public Y Y Y Y
10. ACCESS MODIFIER AND INHERITANCE
• Inherits features of parent’s object/class to the child’s object/class.
• Extends keyword is used to inherit the features of superclass.