How does private/protected work?

I wanted to clean up my code, and started adding private and protected where appropriate. But when I tried it out, it didn't seem to affect anything.

I didn't see anything specifically about it, but after searching I wondered if they'd really only matter if I used a .java file instead of .pde.

After further searching, I think it is because my classes are inner classes. I know that means that they can see outer class private members and vice-versa, but it hadn't occurred to me that they could see into each other. Is this right?

Here's what I used to try it out. I tested it by making a new TryMe2 in setup().

thanks andy

class TryMe1 {
    TryMe1() {
        _myNumber = 6;
    }

    private void myMethod() {
        println("me1 " + _myNumber);
    }

    private int _myNumber;
}

class TryMe2 {
    TryMe2() {
        TryMe1 tm = new TryMe1();
        println("me2 " + tm._myNumber);
        println("me2 => me1");
        tm.myMethod();
    }
}

Answers

Sign In or Register to comment.