Java — Which two are legal declarations for non-nested classes and interfaces?

Difficulty: Medium

Correct Answer: final public class Test {} and abstract public class Test {}

Explanation:


Introduction / Context:
This evaluates legal top-level class and interface declarations.



Concept / Approach:

  • A top-level class can be public or default only (not protected/private).
  • It cannot be both final and abstract at the same time (contradiction).
  • Interfaces cannot be static at the top level.
  • abstract public class Test {} is legal.
  • final public class Test {} is legal.


Final Answer:
final public class Test {} and abstract public class Test {}

More Questions from Declarations and Access Control

Discussion & Comments

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