What will happen if you compile/run the following code?
Class MyClass
{
int x;
MyClass(int i)
{
x = i;
}
public static void main(
string arg[])
{
MyClass m1 = new MyClass(100);
MyClass m2 = new MyClass(100);
if (m1.equals(m2))
{
System.out.println("Both are equal");
}
else
{
System.out.println("Both are unequal");
}
}
}
Answer given is "unequal". Roberts and Heller Certification study guide says that "for x.equals(y) the
test y instanceof x must be true. If this is not the case, then equals() must return false.
Seems like a contradiction with this mock exam, is it?