1public class Base {
2
3 private int x; // field is private
4
5 protected int getX() { // define getter
6 return x;
7 }
8
9 protected void setX(int x) { // define setter
10 this.x = x;
11 }
12}
13//Then you would use it in your child class like this:
14class Child extends Base{
15
16 void foo() {
17 int x = getX(); // we can access the method since it is protected.
18 setX(42); // this works too.
19 }
20}