In this page provide you software multiple choice question which help to many exam like Semester exam, Gate Exam, Railway , ISRO etc.
Java Operator MCQ SET-1
Q.1 Which of the following are arithmetic operators?
+
–
/, %
All of these
Explanation
Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
Q.2 Which of the following are unary operators?
++
—
Both A & B
None of these
Explanation
Unary operators require only one operand. Increment (++) and decrement (–) are the most common examples.
Q.3 Which of the following are classified as Binary operators?
+
–
,
All of these
Explanation
Binary operators require two operands to perform an action. This includes arithmetic, relational, and logical operators.
Q.4 A Unary operator operates on how many values?
One
Two
Three
All of these
Explanation
The term ‘Unary’ is derived from the fact that these operators take exactly one operand.
Q.5 A Binary operator operates on how many values?
One
Two
Three
All of these
Explanation
Binary operators require two operands (e.g., a + b) to perform their specific operation.
Q.6 A Ternary operator operates on how many values?
One
Two
Three
All of these
Explanation
Java features one ternary operator (?:) which takes three operands: a condition, a result for true, and a result for false.
Q.8 Which of the following are Relational operators?
=, instanceof
Both A & B
All of these
Explanation
Relational operators compare two values and return a boolean result. The ‘instanceof’ operator is also categorized here in Java.
Q.9 Which of the following are Bitwise operators?
&
^
|
All of these
Explanation
Bitwise operators perform operations on individual bits. These include AND (&), XOR (^), and OR (|).
Q.10 Which of the following are Logical operators?
&&
||
Both A & B
None of these
Explanation
Logical AND (&&) and Logical OR (||) are used to combine multiple boolean expressions.
Q.11 Which symbol represents the Ternary operator?
&&
? :
Both A & B
None of these
Explanation
The conditional operator (? 🙂 is the only ternary operator in Java, often used as a shorthand for if-else.
Q.12 Calculate the Bitwise AND for (1101) & (1100):
1100
1101
0101
None of these
Explanation
Bitwise AND returns 1 only if both bits are 1. Comparing 1101 and 1100 results in 1100.
Q.13 Calculate the Bitwise OR for (1101) | (1100):
1100
1101
0101
None of these
Explanation
Bitwise OR returns 1 if at least one of the bits is 1. Comparing 1101 and 1100 results in 1101.
Q.14 Calculate the result for Bitwise operation yielding (0011) from (1101) and (1100):
1100
1101
0011
None of these
Explanation
Based on the specific logic provided, the result of this bit manipulation is 0011.
Q.15 Calculate the Bitwise XOR for (1101) ^ (1100):
1100
1101
0001
None of these
Explanation
Bitwise XOR returns 1 only if the bits are different. 1101 XOR 1100 results in 0001.
Q.16 Which of the following is a Relational operator?
==
All of these
Explanation
Less than (), and equal to (==) are all used to establish relationships between values.
Q.17 In the expression '++a', which operator is being used?
Increment operator
Pre-Increment operator
Post-Increment operator
All of these
Explanation
++a’ is a Pre-Increment operator, meaning the value is increased before it is used in the expression.
Q.18 In the expression 'a++', which operator is being used?
Increment operator
Pre-Increment operator
Post-Increment operator
All of these
Explanation
a++’ is a Post-Increment operator, meaning the current value is used first, and then it is increased.
Q.19 What is the output of the Pre-Increment operation for a=6, b=4 (assuming c = ++a * ++b)?
35
24
15
None of these
Explanation
a becomes 7 and b becomes 5. Therefore, 7 * 5 = 35.
Q.20 What is the output of the Post-Increment operation for a=6, b=4 (assuming c = a++ * b++)?
35
24
15
None of these
Explanation
The current values (6 and 4) are used for the calculation first. Therefore, 6 * 4 = 24.