Access Modifiers in Java ,How Access Level Helps in Inheritance and Polymorphism

In java their are 4 access modifiers public,protected,<default>,<package>,private

  • Public-Public  is the access modifiers which shows the highest visibility any class member declare as public can be visible
    1.Within the class.
    2.Within the package.
    3.Outside the package.
  • Protected-Any class member declare as protected are visible
    1.Within the class.
    2.Within the package.
    3.Out side the package but only in the case of is-a relationship.
  • Default-
    If we do not any access modifier to declare then the class member is consider as default member.
    1.Default member are visible within the class
    2.Within the package.
  • Private-
    Private is the access modifier which shows the least visibility if we declare any member as private then it is visible
    1.Only within that classes.

Understanding all java access modifiers

Let’s understand the access modifiers by a simple table.

Access Modifier within class within package outside package by subclass only outside package
Private Y N N N
Default Y Y N N
Protected Y Y Y N
Public Y Y Y Y

If you have any further clarification on Access Modifiers in Java ,How Access Level Helps in Inheritance and Polymorphism please give comment bellow