Hello Ranchers!
class C {
public static void main(String args[]) {
Boolean b1 = Boolean.valueOf(true);//line 1
Boolean b2 = Boolean.valueOf(true);//line 2
Boolean b3 = Boolean.valueOf("TrUe");
Boolean b4 = Boolean.valueOf("tRuE");
System.out.println((b1==b2)+",");//line 3
System.out.println((b1.booleanValue()==b2.booleanValue())+",");
System.out.println((b3.equals(b4));
}
}
The output is - true,true,true
Per my understanding, valueOf method takes a String argument so the above code should not compile as String is not passed as argument to valueOf method at line 1 and line 2.
Even if String is passed as argument to methods at line 1 and line 2, line 3 should yield 'false' as 'valueOf(String s)' method returns an object.Hence, b1 and b2 are two different objects. Therefore, b1==b2 should give false.
Pls explain.
Thanks
Neha Monga