Abstraction hides implementation details and exposes only the functionality the user needs.

The caller knows what to do, but not how it is done internally.

Why Abstraction Is Needed

Instead of making every caller know payment internals:

Expose a simple method:

paymentService.pay();

Examples

app.listen(3000);

This hides socket creation, binding, and listening.

Collections.sort(list);

The caller does not need to know the internal sorting implementation.

Abstraction in Java

Common tools:

Abstraction vs Encapsulation

Abstraction Encapsulation
Hides implementation complexity Hides and protects data
Focuses on what is exposed Focuses on access control
Example: pay() hides payment flow Example: private balance with deposit/withdraw

Interview Notes