Thursday, January 23, 2025
HomeProgrammingAbstraction in Java - GeeksforGeeks

Abstraction in Java – GeeksforGeeks

Abstraction in Java is a core object-oriented programming concept that hides implementation details and shows only the essential features of an object. It allows developers to focus on “what” an object does rather than “how” it does it. Abstraction is achieved using abstract classes and interfaces.

  1. Abstract Classes: Declared with the abstract keyword, they can have abstract methods (without implementation) and concrete methods. Example:
java
abstract class Animal {
abstract void sound(); // Abstract method
}
  1. Interfaces: Define a contract that classes must follow, containing only abstract methods (default methods allowed in Java 8+). Abstraction improves code reusability and flexibility.
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x