public class Account {
private double balance;
public double getBalance() { return balance; }
public void deposit(double amt) {
if (amt > 0) balance += amt;
}
}
// ...Which best describes why balance is private?
- Acheck_circle
To enforce encapsulation; outside code must use methods that validate access and modification
- B
Because private variables run faster
- C
So they cannot be initialized
- D
So static methods cannot use them
Explanation
Encapsulation hides internal state and exposes a controlled interface, allowing validation logic in the methods.