public boolean equals(Object obj)
{
if (obj instanceof Location)
{
Location candidate = (Location) obj; // Cast to a Location object
// Return true if instance states are the same
return (candidate.x == x && candidate.y == y);
}
else
{
return false; // Not a Location object
}
}
public class Location implements Cloneable
super.clone
to make a copy - This is important as the object itself has a clone method (the one being implemented) and if you don't specific super.clone then your implementation will be stuck in an infinite loop of the clone method calling itself repeatedly.
public Location clone( )
{ // Clone a Location object.
Location answer;
try
{
answer = (Location) super.clone( );
}
catch (CloneNotSupportedException e)
{ // This exception should not occur. But if it does, it would probably
// indicate a programming error that made super.clone unavailable.
// The most common error would be forgetting the "Implements Cloneable"
// clause at the start of this class.
throw new RuntimeException
("This class does not implement Cloneable.");
}
return answer;
}
double[][] temps = new double[3][4]; // 3 rows by 4 columns
int[][][] numbers = new int[numPlanes][numRows][numColumns];