I wrote the following class to fiddle around with Comparable/Serializable interfaces.
package testpro;
public class SerialTest implements Comparable {
private int circleSize = 10;
private int getCircleSize() {
return circleSize;
}
@Override
public int compareTo(Object o) {
SerialTest object = (SerialTest) o;
if(getCircleSize()>object.getCircleSize()){ // I can access object.getCircleSize() here, but it's private.. why?
return 1;
}
else if(getCircleSize()<object.getCircleSize()){// I can access object.getCircleSize() here, but it's private.. why?
return -1;
}
else{
return 0;
}
}
}
I'm passing an Object o to compareTo() method, but getCircleSize() is private. So how is that possible, that I've got an access to this? I'm pretty sure C++ wouldn't let it go.