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

Views 12

Answer:

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.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.