1z0-808 Exam QuestionsBrowse all questions from this exam

1z0-808 Exam - Question 85


Given:

And given the commands:

What is the result?

Show Answer
Correct Answer: CD

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'.

Discussion

9 comments
Sign in to comment
iSnoverOption: C
Sep 25, 2022

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.

Joker74Option: C
Sep 6, 2022

if we pass other then true(equals ignore case) as a Boolean argument then it is referred as false.

carlosworkOption: C
Oct 21, 2022

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 );

anmoldev2javaOption: C
Nov 18, 2022

c is ans

akbiyikOption: A
Nov 30, 2022

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.

Vicky_65Option: C
Apr 2, 2023

C is the correct answer

winfred_luOption: C
Jul 7, 2023

false false

dsmsOption: C
Aug 11, 2023

answer is: false false

BelloMioOption: C
Jun 1, 2024

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"