So I'm just looking for clarification. I have an equals method that is able to return the instance variable by cv.ch
of a passed object with out a method to return it. How is this so?
public static class Test {
private int v;
private char ch;
public Test(int v, char ch) {
this.v= v;
this.ch= ch;
}
public boolean equals(Object o) {
if ( this == o ) return true;
if ( o == null || this.getClass() != o.getClass() )
return false;
Test cv = (Test) o;
if ( this.v == cv.v && this.ch == cv.ch)
return true;
return false;
}
}
Edit: I rephrased my question so that it is better understood
The private member variables are accessible to the class that owns them, Test. Any code that's in Test can access those fields, regardless of it does so via "this" or some other variable.
Specifically the JLS says "[I]f the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor."