Oracle
1Z0-803 · Question #46
Given the code fragment: What is the result?
The correct answer is C. Compilation fails. In segment 'if (valid)' valid must be of type boolean, but it is a string. This makes the compilation fail.
Java Basics
Question
Given the code fragment:
What is the result?
Options
- AValid
- Bnot valid
- CCompilation fails
- DAn IllegalArgumentException is thrown at run time
How the community answered
(59 responses)- A3% (2)
- B2% (1)
- C86% (51)
- D8% (5)
Explanation
In segment 'if (valid)' valid must be of type boolean, but it is a string. This makes the compilation fail.
Topics
#compilation errors#syntax rules#type compatibility
Community Discussion
No community discussion yet for this question.