Difficulty: Easy
Correct Answer: private synchronized int e;
Explanation:
Introduction / Context:This question tests knowledge of valid modifiers for class-level (non-local) variables in Java. Some modifiers are allowed for variables, while others are only valid for methods.
Given Data / Assumptions:
Concept / Approach:For variables:
Step-by-Step Reasoning:
protected int a; → Valid.transient int b = 3; → Valid for serialization behavior.private synchronized int e; → Invalid because synchronized cannot be applied to variables.volatile int d; → Valid, ensures visibility across threads.Why Other Options Are Wrong:All except synchronized are legal modifiers for variables.
Common Pitfalls:Confusing synchronized with volatile; synchronized is only for methods/blocks, not variables.
Final Answer:private synchronized int e;
Discussion & Comments