1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
public class GetterSetterExample { private int age = 10; private String name; @Override public String toString() { return String.format("%s (age: %d)", name, age); } public int getAge() { return age; } public void setAge(int age) { this.age = age; } protected void setName(String name) { this.name = name; } }