Q13: What are the differences between an Abstract Class and an Interface?
| Feature | Abstract Class | Interface (Java 8+) |
|---|---|---|
| Inheritance | Single class inheritance (extends) | Multiple interface implementation (implements) |
| State | Can hold state (private instance fields) | Stateless (only public static final constants) |
| Constructors | Supported | Not supported |
| Methods | Abstract, concrete, protected, private methods | abstract, default, static, and private (Java 9+) methods |
Key Takeaways
- Use Abstract Classes for sharing state and identity in class hierarchies.
- Use Interfaces for defining peripheral behavioral capability contracts across unrelated hierarchies.
Knowledge Check
Can a class extend multiple abstract classes in Java?