Java SE 8 Programmer I — Question 33
Which statement best describes encapsulation?
Answer options
- A. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
- B. Encapsulation ensures that classes can be designed so that their methods are inheritable.
- C. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract.
- D. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.
Correct answer: A
Explanation
The correct answer, A, accurately describes encapsulation as it focuses on restricting access to certain components of a class, promoting data hiding. Options B and C address concepts related to inheritance and abstraction, which are not directly related to encapsulation. Option D speaks to polymorphism, which is a separate concept from encapsulation.