Fundamentals · Medium · Free
What is abstraction? How do abstract classes and interfaces differ?
FresherFundamentalsOOP & Language Fundamentals
Abstraction
Abstraction exposes what an object does, not how. Abstract classes can share partial implementation; interfaces define contracts only.
| Abstract class | Interface | |
|---|---|---|
| Fields | Can have state | Only constants (pre-Java 8+ default methods) |
| Use when | Shared base code | Multiple roles / APIs |
| Example | Base HttpClient with retry | Repository<T> |
Backend fresher answer: interfaces for repositories and payment gateways—swap implementations in tests.