Interface vs Abstract Class
When to use which
Interview Relevant: Very common interview question
6 min read
Interface vs Abstract Class
Choosing between interface and abstract class depends on design needs.
- Interface ā multiple inheritance
- Abstract class ā shared state + behavior
- Interface ā contract
- Abstract ā partial implementation
Code Examples
Interface vs abstract class usage
java
1
2interface Flyable {
3 void fly();
4}
5
6abstract class Bird {
7 abstract void sound();
8 void eat() {}
9}
10 Use Cases
- Design decisions
- Framework APIs
Common Mistakes to Avoid
- Using abstract class when interface fits
- Ignoring multiple inheritance limitation