nerdexam
Oracle

1Z0-851 · Question #142

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) {…

The correct answer is A. True. See the full explanation below for the reasoning.

Question

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?

Options

  • ATrue
  • BNot true
  • CAn exception is thrown at runtime.
  • DCompilation fails because of an error at line 12.
  • ECompilation fails because of an error at line 19.

How the community answered

(40 responses)
  • A
    85% (34)
  • C
    10% (4)
  • D
    3% (1)
  • E
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice