Given:
And given the commands:
What is the result?
Given:
And given the commands:
What is the result?
The key to answering this question lies in how the Boolean class handles string inputs. When the Boolean.valueOf(String s) method is called, it returns true if the string is non-null and equal to 'true' (ignoring case); otherwise, it returns false. The second line in the main method constructs a Boolean object directly from the string 'null'. The Boolean constructor also treats any string other than 'true' as false. When the program is executed with '1' and 'null' as arguments, neither '1' nor 'null' equates to 'true', so both boolean 'a' and boolean 'b' will be false. Therefore, the output is 'false false'.
Correct is C, The default valor of a boolean type is false. When the valor is null, in boolean case, it is automatically transformed into false. In the line 2, as the boolean value was not started, so it is false too. Answer False False.
if we pass other then true(equals ignore case) as a Boolean argument then it is referred as false.
boolean valueOf(string s) The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true" https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html#valueOf-boolean- Which means it returns false when a string is equal to "1"
answer is: false false
false false
C is the correct answer
java Test 1 null 1 and null are Strings because args type is String[]. public static Boolean valueOf(String s) { return parseBoolean(s) ? TRUE : FALSE; } If the specified boolean is true, then the string "true" will be returned, otherwise the string "false" will be returned. In this case, if the value is not true, all other String values return false.
c is ans
Answer is C. Remember to run in command line "java Test 1 null". boolean a = new Boolean(Boolean.valueOf(args[0])); boolean b = new Boolean(args[1]); System.out.println( a + " " + b );