Java Concept Explained: What Makes a Class Tightly Encapsulated
A tightly encapsulated class in Java is defined by a single rule: every instance variable must be declared private. Contrary to a common misconception, the presence or absence of getters, setters, or constructors has no bearing on this definition. If even one variable is declared with a non-private access modifier, the entire class fails the tightly encapsulated test. This concept frequently appears in Java interviews and certification exams, making it important for developers to understand the precise definition. The sole criterion is variable visibility, not the methods used to access those variables.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in