Sobes.tech
Middle

What is abstraction in OOP? How do you understand it?

sobes.tech AI

Answer from AI

Abstraction in object-oriented programming is a principle that allows highlighting the essential characteristics of an object while hiding implementation details. It helps focus on what the object does rather than how it does it.

In simpler terms, abstraction enables the creation of interfaces or classes that describe behavior without revealing internal logic.

For example, in Java, you can define an abstract class or interface with methods that must be implemented in subclasses:

abstract class Animal {
    abstract void makeSound();
}

class Dog extends Animal {
    @Override
    void makeSound() {
        System.out.println("Woof");
    }
}

Here, Animal is an abstraction that describes that any animal should be able to make a sound, but it does not specify which one. Concrete classes, like Dog, implement the details.

Abstraction helps reduce system complexity, improve support, and enhance code extensibility.