When a class implements an interface and also extends an abstract class, what is the sequence of abstraction enforcement and implementation that occurs during object instantiation?
easy🧠🧾 Concept Trace Q12 of Q15
OOP & Design Patterns - Abstraction - Abstract Class vs Interface - When to Use Which
When a class implements an interface and also extends an abstract class, what is the sequence of abstraction enforcement and implementation that occurs during object instantiation?
AThe abstract class constructor runs, but interface methods have no implementation to run.
BInterface methods are implemented first, then the abstract class constructor runs.
CThe class must implement interface methods before the abstract class constructor runs.
DThe abstract class's constructor runs first, then interface methods are implemented by the class.
Step-by-Step Solution
Step 1: Understand interface role
Interfaces declare methods but provide no implementation or constructors.
Step 2: Abstract class constructor behavior
Abstract class constructors run during instantiation to initialize shared state.
Step 3: Implementation of interface methods
The class implementing the interface provides method bodies; no constructor or code runs from interface itself.
Final Answer:
Option A -> Option A
Quick Check:
Interfaces define contracts only; abstract class constructors run during instantiation.
Quick Trick:Interface methods have no constructor or implementation to run; abstract class constructors always run.
Common Mistakes:
MISTAKES
Thinking interface methods have constructors or code to execute.
Believing interface implementation order affects constructor execution.
Confusing interface method implementation with constructor invocation.
Trap Explanation:
PITFALL
Options A and B incorrectly imply interfaces have constructors or executable code. Option C confuses implementation order with runtime behavior.
Interviewer Note:
CONTEXT
Tests understanding of the lifecycle and roles of abstract classes vs interfaces during instantiation.
Master "Abstraction - Abstract Class vs Interface - When to Use Which" in OOP & Design Patterns
2 interactive learning modes - each teaches the same concept differently