Java — Which of the following are legal method declarations?
Java Programming
Declarations and Access Control
Difficulty: Medium
Choose an option
-
Aprotected abstract void m1();
-
Bstatic final void m1(){}
-
Csynchronized public final void m1() {}
-
Dprivate native void m1();
Answer
Correct Answer: All of them are legal declarations.
Explanation
Introduction / Context:This evaluates knowledge of valid method declarations and combinations of modifiers in Java.
Concept / Approach:All provided combinations are syntactically legal:
- protected abstract → valid for abstract classes.
- static final → legal (cannot be overridden, final ensures this).
- synchronized public final → legal combination, just unusual.
- private native → legal; native methods are often private.
Step-by-Step:All four compile correctly, though not all are meaningful in all contexts.
Final Answer:All of them are legal declarations.