Skip to content
C

Java Interview Questions

Abstraction Interview Questions

Hiding implementation detail behind abstract classes and interfaces.

Question 1: What is abstraction in Java?

Ans

Abstraction means exposing only the essential behavior of an object while hiding the internal implementation details that a caller doesn't need to know about. In Java, it's achieved mainly through abstract classes and interfaces, which describe what an object can do without necessarily saying how.

Example

java
interface Payment { void pay(double amount); } class UpiPayment implements Payment { public void pay(double amount) { System.out.println("Paid " + amount + " via UPI"); } }

Important Point

A caller using the Payment interface never needs to know how UpiPayment actually processes the payment internally.

Continue Your Preparation