Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Setter for private instance attributes

public class TryPoint {
    public static void main(String[] args) {
        Point a = new Point(7, 3);
        System.out.println(a.getX());
        a.setX(23);
        System.out.println(a.getX());

    }
}

public class Point {
    private int x;
    private int y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return this.x;
    }

    public void setX(int x) {
        this.x = x;

    }
}