Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q7 of 15
Java - Wrapper Classes
Find the error in this code snippet:
Boolean b = Boolean.parseBoolean("yes");
System.out.println(b);
ARuntime exception
BPrints true
CCompilation error due to invalid input
DPrints false
Step-by-Step Solution
Solution:
  1. Step 1: Understand Boolean.parseBoolean behavior

    It returns true only if input string equals "true" ignoring case; otherwise false.
  2. Step 2: Check input "yes"

    Since "yes" is not "true", method returns false, printed as false.
  3. Final Answer:

    Prints false -> Option D
  4. Quick Check:

    parseBoolean("yes") returns false [OK]
Quick Trick: parseBoolean returns true only for "true" string [OK]
Common Mistakes:
  • Expecting true for any non-empty string
  • Assuming compilation or runtime error
  • Confusing parseBoolean with valueOf

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes