Abstract Class vs Interface Interview Questions
What is the difference between an abstract class and an interface? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is the difference between an abstract class and an interface?
An interface is a capability contract. A class can implement many. An abstract class is a partial implementation with shared fields and maybe a constructor. You only get one class superclass in Java and C#. I use an interface when I want Payable or Comparable. I use an abstract class when several implementations share state and a template-method flow — validate, then execute, then audit. Java 8 default methods exist, but I keep them thin so I do not accidentally build a second inheritance tree. In Python I would mention ABC versus Protocol if they are in a Python round.
When do you still choose an abstract class?
When I need shared state or a template method with a protected helper. Interfaces should not hold instance fields. Capability without state is an interface. Two shared utilities are a helper, not a parent class.
Why can a class implement many interfaces but extend only one class?
Multiple capabilities without multiple inheritance of state. A class can be Comparable and Serializable. One superclass. I design extra roles as interfaces. Default-method clashes are the remaining diamond.
Would you add a new marker interface today?
Serializable is the classic empty marker. Today I would often use an annotation. I would not invent a new empty interface unless a framework requires it.
How do you test code that depends on an interface?
I inject a fake. FakePaymentGateway in tests. That is DIP plus interface. Abstract classes can use a test subclass, but interfaces are cleaner. Interviewers want tests, not only UML.
Practice with AI mock interviews
Run OOP mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required