This was an exam question which I couldn't complete.
How do you get the following java code to print false by only editing code within the MyClass constructor?
public class MyClass{ public MyClass(){ } public static void main(String[] args) { MyClass m = new MyClass(); System.out.println(m.equals(m)); } }
You are NOT allowed to override the equals method, or change any of the code within the main method. The code must run without the program crashing.
According to my research, you can't set a Java object reference to null when you instantiate a class. So I'm officially stumped.