How do abstraction and inheritance solve different problems?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Abstraction describes the capabilities a caller needs without exposing every implementation detail. A payment interface might offer charge and refund operations. Inheritance creates a subtype relationship that can also share implementation. A card payment and a wallet payment may implement the same abstraction without inheriting from a common concrete class. Use abstraction to define a stable contract; use inheritance only when the subtype can honor the parent’s behavioral promises. Sharing a few similar methods is not enough reason to create an inheritance hierarchy.
Related Questions in Software Engineering & OOP
Explain the SOLID Principles of Object-Oriented Software Engineering with Examples
Intermediate level • 623 views
Explain ACID properties in relational databases and how different Transaction Isolation Levels prevent concurrency anomalies.
Intermediate level • 152 views
A notification class has growing email, SMS, and push conditionals. How would you refactor it?
Medium level • 5 views
How does encapsulation protect an object’s rules? Explain using a bank account.
Easy level • 4 views
What is the Liskov substitution principle, and why can a square-as-rectangle hierarchy violate it?
Medium level • 4 views