Java Operators Quiz: 25 MCQ Questions with Answers

Yogi Siddeswara 0
STUDYECRAT Java : Operators
60s
Java Operators

Prove your skills in this interactive quiz

💻

Live Code

Run snippets directly

⏱️

Timed

60s per question

🏆

Scored

Earn 3D badges

Java Operators: Key Interview Points

1. Operator Precedence

System.out.println(5 + 3 * 2); // 11 (not 16)
// Order: () → * / % → + - → << >> → == != → & → ^ → | → && → ||
  • Highest: Parentheses ()
  • Common Trap: + has lower precedence than *

2. Prefix vs Postfix Increment

int x = 5;
System.out.println(x++); // 5 (postfix: use then increment)
System.out.println(++x); // 7 (prefix: increment then use)

Critical in loop conditions and complex expressions.

3. Short-Circuit Evaluation

&& and ||

if (false && (5/0 == 0))
// No error: skips 2nd condition

Non-Short-Circuit

& and |
// Always evaluate both sides

4. Bitwise Magic

System.out.println(5 & 3); // 1 (AND)
System.out.println(5 | 3); // 7 (OR)
System.out.println(~5); // -6 (NOT)
System.out.println(5 << 2); // 20 (left shift = *4)
  • Interview Favorite: Swapping variables without temp: x = x ^ y; y = x ^ y; x = x ^ y;

5. Compound Assignment Gotchas

int x = 10;
x += x -= x *= x; // -80 (right-to-left evaluation)

byte b = 5;
b = b + 2; // Error
b += 2; // Valid (auto-casts)

💡 Pro Interview Tip

90% of interview operator questions test these 5 concepts. Practice writing the outputs of nested operators like x = ++x + x++ on paper - whiteboard coding often focuses on these!


Java Operators Quiz: 25 MCQ Questions with Answers

Post a Comment

0 Comments