What do you understand by private protected and public modifiers

What do you understand by private protected and public modifiers

Answer : It use to hide data with the code where it manipulates. Though encapsulation also provide very important attribute called access control. Through encapsulation you can control which part will have access to the member of a class. In java access specifiers are private, protected and public and it also defines default access level. Below table shows how these variable control access when define i the class:

Access Levels

Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N

Leave a Reply

Your email address will not be published. Required fields are marked *