Java MCQ Questions and Answers on Logical Operators 2

Study and learn Java MCQ questions and answers on Logical Operators and their priorities. Attend job interviews easily with these Multiple Choice Questions. You can download these questions in PDF format. Just choose Print and select PDF as the format in Chrome or any other browser.

Go through Java Theory Notes on Logical Operators before reading questions.



1) What happens to the Second operand/expression if the first operand is FALSE with a Short Circuit AND (&&) operator?
A) Second operand/expression is evaluated and AND is applied.
B) Evaluation of Second operand/expression is skipped.
C) The compiler starts taking more memory
D) The compiler starts taking more CPU power.
Answer [=]
Answer[=]
2) What happens to the Second Operand/expression if the first operand is TRUE with a Short Circuit OR (||) operator in Java?
A) Second expression/operand is evaluated and OR is applied to both operands
B) Evaluating the Second expression/operand is skipped
C) The compiler starts taking more memory
D) The compiler starts taking more CPU power
Answer [=]
Answer[=]
3) What is the output of an Exclusive OR (^) operation if one of the operands/expressions is TRUE?
A) false
B) true
C) true or false
D) None of the above
Answer [=]
Answer[=]
4) What is the output of an Exclusive OR(^) operation, if one of the operands is false?
A) false
B) true
C) true or false
D) None of the above
Answer [=]
Answer[=]
5) Which is the Logical operator in Java that has the highest priority among all other logical operators?
A) Short Circuit AND (&&)
B) AND (&)
C) NOT (!)
D) Exclusive OR (^)
Answer [=]
Answer[=]
6) Among the Logical operators, AND (&) and Short Circuit AND (&&), which has higher priority?
A) AND (&)
B) Short Circuit AND (&&)
C) Both have same priority
D) None of the above
Answer [=]
Answer[=]
7) Among the logical operators, OR (|) and Short Circuit OR (||), which operator has higher priority?
A) OR (|)
B) Short Circuit OR (||)
C) Both have the same priority
D) None of the above
Answer [=]
Answer[=]


 

8) Among the logical operators, OR (|), Short Circuit OR (||) and Exclusive OR (^), which operator has higher priority?
A) OR (|)
B) Short Circuit OR (||)
C) Exclusive OR (^)
D) All operators have the same priority.
Answer [=]
Answer[=]
9) Choose the correct version of Logical Compound Assignment operators in Java below?
A) &=, |=, ^=
B) &&=, ||=, !=
C) A and B
D) None of the above
Answer [=]
Answer[=]
10) What is the output of the Java code snippet below?
byte a= 1;
if(!a)
{
  System.out.println("FISH");
}
else
{
  System.out.println("CRAB");
}
A) CRAB
B) FISH
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
11) What is the output of the Java code snippet?
int a=25, b=30;
boolean c = a>25 & b<40;
if(c)
{
  System.out.println("RABBIT");
}
else
{
  System.out.println("GOOSE");
}
A) RABBIT
B) GOOSE
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
12) What is the output of the Java code snippet?
int a=25, b=30;
boolean c = a>25 | b<40;
if(c)
{
  System.out.println("RABBIT");
}
else
{
  System.out.println("GOOSE");
}
A) RABBIT
B) GOOSE
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
13) What is the output of the Java code snippet?
int a=3, b=8;
boolean c = a>5 && ++b>6;
System.out.println(b);
A) 8
B) 9
C) 6
D) Compiler error
Answer [=]
Answer[=]
14) What is the output of the Java code snippet?
int a=5, b=9;
boolean c = a>1 || b++<10;
System.out.println(b);
A) 9
B) 10
C) 8
D) Compiler error
Answer [=]
Answer[=]


 

15) What is the output of the Java code snippet?
int a=4, b=6, c=8;
boolean d = a>5 && b>5 & c++<10;
System.out.println(c);
A) 8
B) 9
C) 10
D) Compiler error
Answer [=]
Answer[=]
16) What is the output of the Java code snippet?
int a=4, b=8;
boolean c = a>1 ^ b<10;
if(c)
{
  System.out.println("TREE");
}
else
{
  System.out.println("BIRD");
}
A) TREE
B) BIRD
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
17) What is the output of the Java code snippet?
int a=5;
boolean b = a>1 || false;
b ^= false;
System.out.println(b);
A) false
B) true
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
18) What is the output of the Java code snippet?
int a=4, b=8;
boolean c = a>2 ^ b<10 & false;
System.out.println(c);
A) false
B) true
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
19) What is the output of the Java code snippet?
int a=3, b=1;
int c = a & b;
System.out.println("CAT " + c);
A) CAT true
B) CAT 1
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
20) If an AND (&) operator is applied with two integers, what is this operator?
A) Boolean operator
B) Bitwise operator
C) Logical operator
D) Arithmetic operator
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.