"New Java programmers might ask if one Alpha object can access the private members of another Alpha object. This is illustrated by the following example. Suppose the Alpha class contained an instance method that compared the current Alpha object (this) to another object based on their iamprivate variables: class Alpha { private int iamprivate; boolean isEqualTo(Alpha anotherAlpha) { if (this.iamprivate == anotherAlpha.iamprivate) return true; else return false; } }
This is perfectly legal. Objects of the same type have access to one another's private members. This is because access restrictions apply at the class or type level (all instances of a class) rather than at the object level (this particular instance of a class). "
What I don't understand about this passage is how the iamprivate variable got a value at all. Since no value was given to it in the Alpha class shown, how can there be a comparison between "this.iamprivate" and "anotherAlpha.iamprivate variable? The iamprivate variable is declared private, so no other class can give it a value, right? Can the Alpha class exist in more than one place in the program?