✏️ Explanatory Question
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.