Why Java class Cannot be Private ? | Java Online Training
This Java Online Training “Why Java class Cannot be Private?” page explains clearly why we cannot define java class as private in the application and reasons with diagrams.
Private class in Java:
- “private” is an access modifier in java.
- We can apply ‘private’ to class members such as variables, methods and constructors.
- ‘private members’ of class can be accessed only with in the class.
- The following diagram explains clearly.
- We cannot apply ‘private’ to class in java application.
- If Complete class(Object) is private, it is not visible to outside objects to communicate.
- Hence no other other class(object) can access the members of private class.
- Such type of objects(private) are useless in the application.