Relational & Logical Operators QuizJ8 Home « Relational & Logical Operators Quiz

Fundamentals Quiz 7

The quiz below tests your knowledge of the material learnt in Fundamentals - Lesson 8 - Relational & Logical Operators.

Question 1 : What values do a and b hold after the following expressions?

boolean a = true;boolean b = false;if (a | b) {System.out.println(true);}
- The <code>|</code> logical operator checks both <code>a</code> and <code>b</code> for <code>true</code> and so the answer is <code>true</code> as <code>b</code> is <code>true</code>.
Question 2 : What symbol do we use for XOR (exclusive OR)?
- The <code>^</code> symbol is used for XOR (exclusive OR).
Question 3 : When could we use the || short-circuit operator?
- The <code>||</code> Short circuit operator can be more efficient when the first operand of an OR has a <code>true</code> value and therefore the OR criteria is met.
Question 4 : What symbol do we use for NOT?
- The <code>!</code> symbol is used for NOT.
Question 5 : What is the result of a logical operator?
- The result of a logical operation is the boolean type.
Question 6 : When could we use the && short-circuit operator?
- The <code>&&</code> Short circuit operator can be more efficient when the first operand of an AND has a <code>false</code> value and therefore the AND criteria is NOT met.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz on Java is all about Assignment Operators.