Java MCQs – Operators and Expressions

This article presents a series of Multiple-Choice Questions (MCQs) that will test your knowledge of Java operators and expressions. Whether you are a beginner looking to reinforce your understanding or an experienced developer sharpening your skills, these MCQs will help you deepen your comprehension of this crucial aspect of Java programming.

As a Java developer, understanding operators and expressions is fundamental to writing efficient and effective code. Operators are symbols that perform specific operations on variables, constants, and expressions, while expressions are combinations of these elements that produce a single value.

1.) What is the result of the expression 2 + 3 * 2?

A) 10
B) 8
C) 12
D) 2

Answer: Option B

Explanation: In Java, the multiplication operator (*) has higher precedence than the addition operator (+).

2.) What is the result of the expression “Java” + “CodePoint”?

A) Java
B) Javacodepoint
C) JavaCodePoint
D) Runtime exception

Answer: Option C

Explanation: In Java, the + operator is used for both addition (for numeric types) and concatenation (for strings). When used with strings, it concatenates the two strings together.

3.) What is the result of the expression 11 % 3?

A) 0
B) 1
C) 2
D) 3

Answer: Option C

Explanation: The % operator is the modulus operator, which gives the remainder when the left operand is divided by the right operand. So, 11 % 3 gives the remainder of 11 divided by 3, which is 2.

4.) What is the result of the expression 1 > 3 && 4 < 5?

A) true
B) false
C) Runtime exception
D) The output cannot be determined.

Answer: Option B

Explanation: In Java, the “&&” operator is the logical AND operator. It returns true if both operands are true; otherwise, it returns false.

5.) Which operator is used to check if two values are not equal in Java?

A) !=
B) ==
C) !==
D) <>

Answer: Option A

Explanation: In Java, the “!=” operator is used to check if two values are not equal.

6.) What is the result of the expression 1 + 2 + “0”?

A) 3
B) 30
C) “30”
D) 120

Answer: Option C

Explanation: In Java, when the “+” operator is used with a string and any other data type, it performs string concatenation. So, 1 + 2 is evaluated first as 3 (numeric addition), and then “0” (a string) is concatenated to the result, resulting in “30”.

7.) What is the result of the expression 2 + 2 * 2 / 2 – 2?

A) 2
B) 4
C) 8
D) 0

Answer: Option A

Explanation: In Java, the order of evaluation for arithmetic operations follows the rules of precedence. The multiplication and division operations have higher precedence than addition and subtraction. So, the expression is evaluated as follows: (2 + (2 * 2) / 2) – 2 = 2.

8.) What is the purpose of the “++” operator in Java?

A) To perform subtraction
B) To perform addition
C) To decrement a variable by 1
D) To increment a variable by 1

Answer: Option D

9.) Which operator is used for logical AND in Java?

A) &
B) &&
C) !
D) ||

Answer: Option B

Explanation: In Java, the “&&” operator is used for logical AND.

10.) Which operator is used for assignment in Java?

A) =
B) ==
C) +=
D) :=

Answer: Option A

Explanation: In Java, the “=” operator is used for assignment.

Leave a Reply

Your email address will not be published. Required fields are marked *