1Z0-809 · Question #125
What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?
The correct answer is A. Encapsulation. Encapsulation is the Java concept that uses access modifiers (private, protected, public) to restrict direct access to a class's fields, typically exposing them only through getter/setter methods - this is exactly what "protecting variables and hiding them within a class"…
Question
Options
- AEncapsulation
- BInheritance
- CAbstraction
- DInstantiation
How the community answered
(41 responses)- A76% (31)
- B15% (6)
- C2% (1)
- D7% (3)
Explanation
Encapsulation is the Java concept that uses access modifiers (private, protected, public) to restrict direct access to a class's fields, typically exposing them only through getter/setter methods - this is exactly what "protecting variables and hiding them within a class" describes. Inheritance (B) is about a subclass acquiring properties from a parent class, which has nothing to do with access control. Abstraction (C) is about hiding implementation complexity behind interfaces or abstract classes, not about protecting instance variables specifically. Instantiation (D) simply refers to creating an object from a class using new, and is unrelated to access control.
Memory tip: Think of Encapsulation as putting data in a capsule - sealed off from the outside, with only controlled openings (getters/setters) to access what's inside.
Community Discussion
No community discussion yet for this question.