Summary

Abstraction is a fundamental concept in object-oriented programming that involves hiding the complex implementation details of a system and exposing only the necessary and relevant features. It allows programmers to focus on what an object does rather than how it does it. In Java, abstraction is achieved using abstract classes and interfaces.

In Short

Showing the feature and hiding internal detail or implementation.

Example Code

// Abstract class
abstract class Animal {
    // Abstract method (does not have a body)
    public abstract void makeSound();

    // Regular method
    public void sleep() {
        System.out.println("Zzz...");
    }
}

// Subclass (inherits from Animal)
class Dog extends Animal {
    public void makeSound() {
        System.out.println("Woof");
    }
}

public class Main {
    public static void main(String[] args) {
        Dog myDog = new Dog();
        myDog.makeSound(); // Outputs: Woof
        myDog.sleep();     // Outputs: Zzz...
    }
}

If we want 100% abstraction then use the interfaces which will provide you better data security.

Abstract class provide you 0 to 100 abstraction of the class

In simple word Abstraction means

Implementation ⇒ hide && Feature ⇒ show