108k views
5 votes
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.println((o1 == o2) + " " + (o2));
}
}

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

1 Answer

4 votes

Final answer:

The output of the code is false false.

Step-by-step explanation:

The output of the code would be false false.

In the code, two different instances of the Object class are created and assigned to variables o1 and o2 respectively.

Since each variable refers to a different object instance, o1 == o2 would evaluate to false.

The System.out.println statement then prints false false to the console.

User Mahmoud Aladdin
by
8.6k points