class Golfball {
private String brand;
private String make;
private int compression;
...
public String brand() {
return brand;
}
...
public boolean equals(object obj) {
if (this == obj)
return true;
if (obj!=null && getClass() == obj.getClass())
{
Golfball gb = (Golfball)obj; // Classes are equal, downcast.
if (brand.equals(gb.brand()) && // Compare atrributes.
make.equals(gb.make()) &&
compression == gb.compression())
return true;
}
return false;
}
}
class MyGolfball extends Golfball {
public final static byte TwoPiece = 0;
public final static byte ThreePiece = 1;
private byte ballConstruction;
...
public byte constuction() {
return ballConstruction;
}
...
public boolean equals(Object obj) {
if (super.equals(obj))
{
MyGolfball bg = (MyGolfball)obj; // Classes equal, downcast.
if (ballConstruction == gb.construction())
return true;
}
return false;
}
}
End of Listing