Bird
Raised Fist0

A class implements an interface that declares three methods. The class provides implementations for two methods but forgets the third. What happens during compilation or runtime?

easy🧠🧾 Concept Trace Q3 of Q15
OOP & Design Patterns - Abstraction - Abstract Class vs Interface - When to Use Which
A class implements an interface that declares three methods. The class provides implementations for two methods but forgets the third. What happens during compilation or runtime?
ACompilation fails because the class does not implement all interface methods.
BCompilation succeeds but runtime throws an error when the third method is called.
CCompilation succeeds and the third method is inherited from Object class.
DCompilation succeeds and the third method is treated as optional.
Step-by-Step Solution
Solution:
  1. Step 1: Recall interface contract enforcement

    Interfaces require all declared methods to be implemented by the class unless the class is abstract.
  2. Step 2: Analyze consequences of missing method

    Missing implementation causes compilation failure because the contract is broken.
  3. Step 3: Verify runtime behavior

    Code does not compile, so runtime errors do not occur.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Interface methods must be implemented or compilation fails [OK]
Quick Trick: Interfaces require full implementation at compile time [OK]
Common Mistakes:
MISTAKES
  • Thinking missing methods cause runtime errors only
  • Assuming default Object methods cover interface methods
  • Believing interface methods are optional
Trap Explanation:
PITFALL
  • Candidates confuse interface enforcement with optional or default behavior, missing compile-time checks.
Interviewer Note:
CONTEXT
  • Tests knowledge of interface contract enforcement and compile-time checks.
Master "Abstraction - Abstract Class vs Interface - When to Use Which" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes