Here's a class named BlackBox. The class overrides equals and hashCode methods.
What does this code output?
public class BlackBox {
private final int additive;
private int input1;
private int input2;
public BlackBox(int add){
additive = add;
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BlackBox)) return false;
BlackBox that = (BlackBox) obj;
return additive == that.additive
&&
input1 == that.input1
&&
input2 == that.input2;
}
public static void main(String[] args) {
BlackBox bb1 = new BlackBox(10);
Object bb2 = new BlackBox(10);
System.out.print(bb1.equals(bb2) + " ");
System.out.print(bb2.equals(bb1));
}
}