Suppose we have this code:
public class HelloWorld
{
public static void main(String[] args)
{
OtherClass myObject = new OtherClass(7);
OtherClass yourObject = new OtherClass(4);
System.out.print(myObject.compareTo(yourObject));
}
}
public class OtherClass
{
private int value;
OtherClass(int value)
{
this.value = value;
}
public int compareTo(OtherClass c)
{
return this.value - c.value;
}
}
apparently In the compareTo
method, I am able to access c.value even when i am accessing it outside of the c
object?