Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Java - Interfaces
Identify the error in this code snippet:
interface A { void display(); } 
interface B { void display(); } 
class C implements A, B { } 
public class Test { 
  public static void main(String[] args) { 
    C obj = new C(); 
    obj.display(); 
  } 
}
AClass C should extend interfaces, not implement.
BClass C must implement the display() method.
CInterfaces cannot have methods with the same name.
DNo error, code runs fine.
Step-by-Step Solution
Solution:
  1. Step 1: Check interface method requirements

    Interfaces A and B declare abstract method display().
  2. Step 2: Verify class C implementation

    Class C does not implement display(), so it must be declared abstract or implement the method.
  3. Final Answer:

    Class C must implement the display() method. -> Option B
  4. Quick Check:

    Implement all interface methods = C [OK]
Quick Trick: Implement all interface methods or declare class abstract [OK]
Common Mistakes:
  • Assuming interfaces cannot share method names
  • Forgetting to implement interface methods
  • Using 'extends' instead of 'implements' for interfaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes