CHAPTER 17
Beginner
Encapsulation and Abstraction
Updated: May 17, 2026
5 min read
# CHAPTER 17
Encapsulation and Abstraction
1. Introduction
Encapsulation and Abstraction are two pillars of OOP that protect and simplify your code. Encapsulation hides the internal data; Abstraction hides the implementation complexity. Together they create robust, secure, and user-friendly software.2. Encapsulation — Data Hiding
Make fieldsprivate and provide controlled access via public getter/setter methods.
java
Why? Direct access (account.balance = -1000) bypasses validation. Getters/setters enforce rules.
3. Abstraction — Hiding Complexity
Show only WHAT an object does, not HOW it does it.
java
4. Abstract Classes
- Cannot be instantiated directly.
- Can have abstract methods (no body) and concrete methods (with body).
- Child classes MUST implement all abstract methods.
java
5. MCQ Quiz with Answers
Question 1
Encapsulation uses which access modifier primarily?
Question 2
What provides controlled access to private fields?
Question 3
Can you create an object of an abstract class?
Question 4
An abstract method has:
Question 5
Abstraction means:
Question 6
A class with all private fields and public getters/setters demonstrates:
Question 7
Can an abstract class have constructors?
Question 8
If a class has one abstract method, the class must be:
Question 9
Can an abstract class have concrete methods?
Question 10
What is data hiding?
6. Interview Questions
- Q: Difference between Encapsulation and Abstraction?
- Q: Why should fields be private? What problem does it solve?
- Q: Can an abstract class have a constructor even though it can't be instantiated?