I am working on some practice questions for the OCP 8.
One question featured a class with private fields and private getter methods. The correct answer was that this code violates encapsulation because the getter methods should have been public.
public class A {
private String a;
private String getA() { return a; }
}
However, another question featured a class with private fields and no getter methods at all. The correct answer was that this code follows encapsulation principles.
public class A {
private String a;
}
Assuming all data fields are private, shouldn't the order of most encapsulated to least be no getter methods, private getter methods and public getter methods?
I know my question might sound opinion-based, but the exam is not.