Bird
0
0

Which of the following is the correct syntax to declare an interface in Java?

easy📝 Syntax Q3 of 15
Java - Interfaces
Which of the following is the correct syntax to declare an interface in Java?
Ainterface MyInterface { void method(); }
Bclass MyInterface { void method(); }
Cinterface MyInterface() { void method(); }
DMyInterface interface { void method(); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall interface declaration syntax

    Interfaces use the keyword 'interface' followed by the name and method signatures without bodies.
  2. Step 2: Identify correct syntax

    interface MyInterface { void method(); } correctly declares an interface with a method signature and no parentheses after the name.
  3. Final Answer:

    interface MyInterface { void method(); } -> Option A
  4. Quick Check:

    Interface syntax = Correct declaration [OK]
Quick Trick: Use 'interface' keyword without parentheses [OK]
Common Mistakes:
  • Using class keyword instead of interface
  • Adding parentheses after interface name
  • Placing interface keyword after name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes