Key points about private Java Keyword
- 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 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.
private Java Keyword Example
Summary
- A private (inner) class, method or field may only be referenced from within the class in which it is declared. It is not visible outside the class or to subclasses.
- The default access for all class members is package access, meaning that unless a specific access control modifier is present the class members are accessible from within any class in the same package.
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner

Comments
Post a Comment
Leave Comment