← Quiz: Java Classes and Objects: all 10 questions
Quiz: Java Classes and Objects · Question 9 of 10
What is the main benefit of private fields with public methods (encapsulation)?
What is the main benefit of private fields with public methods (encapsulation)?
- A.The program runs faster
- B.Fields use less memory
- C.The class can check every change (for example, no negative balance) and change its internals without breaking other code
- D.Other classes can change the fields directly
Answer & explanation
Correct answer: The class can check every change (for example, no negative balance) and change its internals without breaking other code
Hiding the data lets the class protect its own rules; outside code can use only the methods it offers.
Can you get the rest right without peeking?
Take the timed Quiz: Java Classes and Objects quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →