ACCESS MODIFIER AND
INHERITANCE
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
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:
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:
PUBLIC ACCESS MODIFIER
• It can be access with any classes.
• It is widest scope among all other modifiers.
• Example of Public Access Modifier is:
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
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.
THANK YOU!!

Access modifier and inheritance

  • 1.
  • 2.
    DEFINATION OF ACCESSMODIFIER • 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:
  • 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:
  • 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:
  • 9.
    SCOPE OF ACCESSMODIFIERS 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 ANDINHERITANCE • Inherits features of parent’s object/class to the child’s object/class. • Extends keyword is used to inherit the features of superclass.
  • 11.