Java — Which three are valid method signatures in an interface?

Java Programming Declarations and Access Control Difficulty: Medium
Choose an option
  • A
    private int getArea();
  • B
    public float getVol(float x);
  • C
    public void main(String [] args);
  • D
    public static void main(String [] args);
  • E
    boolean setFlag(Boolean [] test);

Answer

Correct Answer: public float getVol(float x);, public void main(String [] args);, boolean setFlag(Boolean [] test);

Explanation

Introduction / Context:This checks which method signatures are allowed inside interfaces.

Concept / Approach:

  • Interface methods are implicitly public and abstract (before Java 8).
  • private is not allowed for interface methods until Java 9 (the question assumes older standard, so it is invalid).
  • public static void main(String[] args) is not valid inside traditional interfaces (static methods in interfaces are only allowed in Java 8+).

Step-by-Step:

Option B: Valid abstract method.Option C: Valid abstract method (main like any method).Option E: Valid abstract method.

Final Answer:2, 3, and 5

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