public class Test { public static void main(String[] args) { Object o1 = new Object(); Object o2 = new Object(); System.out.print((o1 == o2) + " " + (o1.equals(o2))); } }

What is the output of the following code:


public class Test {
  public static void main(String[] args) {
    Object o1 = new Object();
    Object o2 = new Object();
    System.out.print((o1 == o2) + " " + (o1.equals(o2)));
  }
}


A. false false
B. true true
C. false true
D. true false

The correct answer is A

Explanation: o1 == o2 is false, since o1 and o2 are two different objects. o1.equals(o2) is false since the equals method returns o1 == o2 in the Object class.


Java

Learn More Multiple Choice Question :