Abstraction is the process of hiding the complex implementation details and showing only the essential features of an object. It allows you to focus on the what a system does, rather than how it does it. The goal is to reduce complexity and increase efficiency by providing a simpler interface.
Note:
- Abstraction uses only the abstract keyword.
- Without an abstract keyword, you cannot use the abstraction.
Key Points about Abstraction
Hiding Complexity: With abstraction, you focus on what is necessary and hide the unnecessary complexities.
Exposing only Essential Features: In real-world examples, an object might have many properties and methods, but you only expose what is needed and hide others.
Types of Abstraction
We can achieve Abstraction in two ways.
1. Using Abstract Classes
2. Using Interfaces
Java Abstraction – Interview Questions
Q 1: What is abstraction in Java?
Q 2: Why is abstraction used?
Q 3: How is abstraction achieved in Java?
Q 4: Does abstraction support code reusability?
Q 5: Can abstraction be partial?
Java Abstraction – Objective Questions (MCQs)
Q1. Which of the following best defines abstraction in Java?
Q2. Which keyword is used to declare an abstract class in Java?
Q3. What happens if an abstract class has a method without implementation and the subclass does not override it?
Q4. Can an abstract class have a constructor in Java?
Q5. Which of the following statements about abstract methods is true?