Multiple choice technology programming languages

Given: 11. public void testIfA() { 12. if (testIfB("True")) { 13. System.out.println("True"); 14. } else { 15. System.out.println("Not true"); 16. } 17. } 18. public Boolean testIfB(String str) { 19. return Boolean.valueOf(str); 20. } What is the result when method testIfA is invoked?

  1. True

  2. Not true

  3. An exception is thrown at runtime.

  4. An exception is thrown at runtime

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Boolean.valueOf("True") returns a Boolean object wrapping true. When used in an if condition, any non-null Boolean evaluates to true, so the if block executes and prints "True". The method parses the string "True" as truthy.