Levels Of Access Control in Java

In this topic, you will learn about, various levels of access control in Java.

Access control specifies with the help of access specifier where in java language access specifier implement the data-hiding concept and also specify hiding properties. Java uses three types of access control public, private, and protected where public type access control represents level 1 because the public can be access outside of the class, and its offers the facility to use a private member of the class.

Private member specifies 2nd level access control because private only accessible by using a public member of the class.

Protected member specifies level-3 access control. so, the protected members can be accessed by using private member only.

Difference between public, private, and protected are as follows:

PUBLIC:

  1. By default, java class member declared publically.
  2. A public member can be accessed outside of the class using the object.
  3. the public can be inherited by a derived class.

PRIVATE:

  1. To specify a private member use a private keyword.
  2. A private member is only accessible by using a private member of the class.
  3. A private member also inherits by a derived class.

PROTECTED:

  1. To create protected members use the protected keywords.
  2. Protected member access with the help of a private member of the class.
  3. Protected cannot be inherited by a derived class.

Comment below if you have queries related to the above topic, Levels Of Access Control in Java.

See also  Introduction to Java