Here's a class named BlackBox. The class has equals and hashCode methods.
What does this code output?
Tip: Class BlackBox doesn't override equals method.
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();
}
public boolean equals(BlackBox 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(11);
Object bb2 = new BlackBox(11);
System.out.print(bb1.equals(bb2) + " ");
System.out.print(bb2.equals(bb1));
}
}