How come dont get a NullPointerException when I call w.getX() in constructor Turtle(...) but when i call it in method getX() i do.
I'm guessing it has something to do with the public and private statements?
public class Turtle {
    int x, y;
    private boolean pen;
    private double rikt;
    private SimpleWindow w;
    public Turtle(SimpleWindow w, int x, int y) {
        w.moveTo(x, y);
        System.out.println(w.getX());
        rikt = Math.PI / 2;
        pen = false;
    }
    public int getX() {
        return w.getX();
    }
    public int getY() {
        return w.getY();
    }
}
The main looks like this:
public class TurtleDrawSquare {
     public static void main(String[] args) {
        SimpleWindow w = new SimpleWindow(600, 600, "TurtleDrawSquare");
        Turtle t = new Turtle(w, 300, 300);
        t.penDown();
        for (int i = 0; i < 4; i++) {
            t.forward(100);
            t.left(90);
        }
    }
}
 
     
    