Java — Which is a valid declaration within an interface?

Difficulty: Easy

Correct Answer: public static short stop = 23;

Explanation:

Introduction / Context:This question checks the rules for declarations inside an interface in Java.

Concept / Approach:Inside interfaces:

  • Variables must be public, static, and final implicitly (even if not written).
  • Methods must be abstract (before Java 8) or default/static (Java 8+).
  • Access modifiers like protected and transient are invalid here.

Step-by-Step:

Option A: Legal. Interfaces can contain constants (public static final short stop = 23;).Option B: protected not allowed inside interface variables.Option C: transient is not valid for constants.Option D: final void madness(...) is invalid because interface methods cannot be final (they must be overridden unless default/static).

Final Answer:public static short stop = 23;

Discussion & Comments

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