Careeroza
Abstract Class vs Interface
Comparison
| Feature | Abstract class | Interface |
|---|---|---|
| Instantiate directly | no | no |
| Constructor / state (backing fields) | yes | no |
| Default (non-abstract) functions | yes | yes |
| How many can a class extend | one | many |
| Members open by default | only abstract ones | yes |
| Typical use | shared base with state (BaseActivity, Account) | capabilities / contracts (Clickable, Repository) |
Rule of Thumb
- Start with an interface. It keeps classes flexible and easy to fake in tests.
- Use an abstract class when subclasses must share state or constructor logic.
- A class can do both:
class Savings : Account("x"), Printable, Exportable.