A class Owl has data members kind and weight, and overrides equals method. It also overrides hashCode, because any class that overrides equals should override hashCode too:
// import java.util.Objects;
class Owl {
public Owl( String k, int w ) {
kind = k;
weight = w;
}
@Override
public boolean equals(Object o) {
return o == this ||
( o instanceof Owl &&
Objects.equals(((Owl)o).kind, kind) &&
((Owl)o).weight == weight );
}
// Override hashCode also
@Override
public int hashCode() {
return Objects.hash(kind, weight);
}
// ... more methods
private String kind;
private int weight;
}
Class Owl is used as follows:
Owl o1 = new Owl("Barn", 20);
Owl o2 = new Owl("Barn", 20);
Object o3 = o1;
Select all the equality tests on o1, o2, and o3 below that would return true: