Java Private Access Modifier Example demonstrates how to control the visibility of a field, method, class, and constructor.
Java Private Access Modifier
A private class member cannot be accessed from outside the class; only members of the same class can access these private members.
- A class cannot be a private except inner classes because inner classes are nothing but again members of the outer class. So members of a class (field, method, constructor and inner class) can be private but not the class itself.
- We can’t create subclasses to that class which has only private constructors.
Below diagram demonstrates the usage of private access modifier and it's visibility:
Access Modifiers
Java
Java Tutorial
Comments
Post a Comment