I've been writing Java for some years, but I still do not understand why this simple example class below actually passes compilation. In this situation, I would make a getter method for myInt, and use that method to fetch the myInt from o in my compareTo method, as myInt is declared private. Could someone please tell me why on earth this is a legal way to access o's myInt?
public class B implements Comparable<B> {
private int myInt = 0;
public int compareTo(B o) {
return myInt-o.myInt;
}
}
Thanks in advance!