Menu

1 / 2

Abstraction in Java

DEV Community·Harini·6 months ago
#1ShvXciA
#java#beginners#basic#software#abstract
Reading 0:00
15s threshold

Abstraction in Java is a core concept of Object-Oriented Programming (OOP). It means hiding unnecessary implementation details and showing only the essential features of an object.

Abstraction focuses on what an object does instead of how it does it.

Example:

When you drive a car, you use the steering wheel, accelerator, and brakes — you don’t need to know how the engine works internally.

How Abstraction is Achieved in Java

In Java, abstraction is implemented using:

Abstract Classes

Declared using the keyword abstract

Can have:

Abstract methods (no body)

Concrete methods (with body)

abstract class Animal { abstract void sound (); // abstract method

void eat () { System . out . println ( "This animal eats food" ); } }

class Dog extends Animal { void sound () { System . out . println ( "Dog barks" ); } }

Enter fullscreen mode

Exit fullscreen mode

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.