Hi all,
I don't quite understand the following question:
class C {
public static void main(
String[] args) {
Boolean b1 = Boolean.valueOf(true);
Boolean b2 = Boolean.valueOf(true);
Boolean b3 = Boolean.valueOf("TrUe");
Boolean b4 = Boolean.valueOf("tRuE");
System.out.print((b1==b2) + ",");
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");
System.out.println(b3.equals(b4));
}}
What is the result of attempting to compile and run the program?
a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. Compile-time error
j. Run-time error
k. None of the above
The answer is true,true,true. What I am not understand is, for b1==b2, why produces true? I think b1 and b2 refer to 2 Boolean instances, and so the addresses of these two instances should be different, and so b1==b2 should false. But why b1==b2 is true?
Thanks,
David