Which of the following can be considered an example of encapsulation?
A) Making all class members public.
B) Using private variables with public getter and setter methods.
C) Allowing direct access to an object's internal state.
D) Not using classes at all.
Answer: B) Using private variables with public getter and setter methods.
Explanation: Encapsulation is achieved by restricting access to an object's internal state (usually through private variables) and providing public methods (getters and setters) to access and modify that state. This helps protect the integrity of the object's data and enforces control over how it is accessed and changed.