Home / Questions / What do you understand by the term data abstraction? Explain with an example.
Explanatory Question

What do you understand by the term data abstraction? Explain with an example.

👁 124 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Data Abstraction: Data abstraction is the concept of hiding the internal details of a class and showing only the essential features. This allows the user to interact with the object at a higher level without worrying about the underlying complexity. It is implemented in Java using abstract classes and interfaces.

Example:


abstract class Shape {
    abstract void draw(); // Abstract method
}

class Circle extends Shape {
    void draw() {
        System.out.println("Drawing a Circle");
    }
}

class TestAbstraction {
    public static void main(String[] args) {
        Shape s = new Circle(); // Object of Circle class
        s.draw();
    }
}

In this example, Shape is an abstract class that hides the details of the draw() method. The Circle class provides the implementation, and the user only interacts with the draw() method.