Given:
3. public class Main { 4. static String s; 5. static Boolean b; 6. static Boolean t1() { return new Boolean("howdy"); } 7. static boolean t2() { return new Boolean(s); } 8. public static void main(String[] args) { 9. if(t1()) System.out.print("t1 "); 10. if(!t2()) System.out.print("t2 "); 11. if(t1() != t2()) System.out.print("!= "); 12. } //from ww w . j av a 2 s . c o m 13. }
Which are true? (Choose all that apply.)
D is correct.
Unboxing automatically converts the Boolean objects to boolean primitives.
The Boolean(String) constructor views null Strings AND Strings that don't have the value of "true" (case-insensitive) to be false.
It's legal for "if" tests to be based on method calls that return a boolean.
Finally, when "==" or "!=" is used to compare a wrapper object with a primitive, the wrapper is unwrapped before the comparison.