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 data-hiding concept and also specify hiding properties. Java uses three types of access control as a public, private and protected where public type access control represent level 1 because the public can be access outside of the class and its offers 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, protected member can be accessed by using private member only.
Difference between public, private and protected are as follows:
- By default, java class member declared publically.
- A public member can be accessed outside of the class using the object.
- the public can be inherited by a derived class.
- To specify private member use a private keyword.
- A private member is only accessible by using a private member of the class.
- A private member also inherits by a derived class.
- To create protected member use protected keyword.
- Protected member access with the help of a private member of the class.
- 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.