Oracle Certified Professional Java Se 11 Developer · Free Practice Question Easy
Question 5
Question ID: UKOCP38050
Consider below code of Test.java file:
- package com.udayankhattry.ocp;
- public class Test {
- public static void main(String[] args) {
- boolean b1 = 0;
- boolean b2 = 1;
- System.out.println(b1 + b2);
- }
- }
What is the result of compiling and executing Test class?
- A 0
- B 1
- C true
- D false
- E Compilation error
Reveal correct answer
Correct answer: E
Explanation
UKOCP38050: In Java language, boolean type can store only two values: true and false and these values are not compatible with int type. Also + operator is not defined for boolean types. Hence, all the 3 statements inside main method causes compilation error.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
