There are two levels of access modifiers such as top level access and member level access.
Top level access
This is related to class definition. A class can be public or package-private.
Declaring as public, a class can be accessed to any class and outside the application as well. Package-private means you can declare a class with any modified by default it will nominate as package-private.
Member level access
This is for member level access modifiers such as properties, methods and so on. This can be chopped in to four modifiers such as public, private, protected and package-private.
Here public and private modifiers’ accessibilities are same as top level access which is described above.
The new two member level modifiers are private and protected.
- Private – This modifier can only be accessed via same class.
- Protected – This modifier can only be accessed via same package.
For further additions package-private modifiers cannot be access via sub classes of out of package.