Java — Which of the following are legal method declarations?

Java Programming Declarations and Access Control Difficulty: Medium
Choose an option
  • A
    protected abstract void m1();
  • B
    static final void m1(){}
  • C
    synchronized public final void m1() {}
  • D
    private 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.

Discussion & Comments
No comments yet. Be the first to comment!
Join Discussion