Difference between public private protected default Access Specifiers

Difference between public private protected default Access Specifiers

OR
What is the difference between public, private, protected and default Access Specifiers?

Answer : 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 *