---
title: "Data abstraction versus encapsulation"
subject: "Object Oriented Programming"
chapter: 1
key: "semester_3/object_oriented_programming:data-abstraction-encapsulation"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/data-abstraction-encapsulation
site: BCT Engineering
---

# Data abstraction versus encapsulation

Object Oriented Programming · Chapter 1: Introduction to Object Oriented Programming

- Asked in: 2072 Kartik, 2+2 marks
- Video: [Abstraction | Encapsulation | OOPs in C++ | Lec-03 | Bhanu Priya](https://www.youtube.com/watch?v=nvrylVckaLU) — Education 4u
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/data-abstraction-encapsulation
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-1

## Question

What is data abstraction? Compare it with encapsulation in C++.

## Short answer

Data abstraction hides implementation details, showing only essential features. Encapsulation binds data and functions into a class, hiding data to prevent accidental change. Abstraction is design-level, encapsulation is implementation-level; encapsulation enables abstraction.

## Answer

#### Data abstraction

Data abstraction means showing only the essential features of an object to the outside world and hiding the background details of how they work. The user knows *what* an object does, not *how* it does it. In C++ it is achieved with classes (public interface and private data) and abstract classes. For example, with `cout << x;` we use the output facility without knowing how characters reach the screen; a `Stack` class offers `push()` and `pop()` while the array and index stay hidden.

#### Comparison with encapsulation

Encapsulation is wrapping data and the functions that work on it into one unit (a class) and restricting direct access to the data.

| Point | Data abstraction | Encapsulation |
|---|---|---|
| Meaning | Hiding implementation details, showing only essentials | Binding data and functions together and hiding the data |
| Level | Design level (what to show) | Implementation level (how to hide) |
| Purpose | Reduce complexity | Protect data and keep integrity |
| Achieved by | Abstract classes, interfaces, public member functions | Classes with `private` / `protected` members |
| Result | User sees a simple interface | Data cannot be changed accidentally |

Encapsulation is the mechanism that makes abstraction possible in C++.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is data abstraction?
   A. Binding data and functions into a class only
   B. Showing only essential features and hiding how they work
   C. Deriving one class from another
   D. Allocating memory at run time
   Answer: B. Abstraction tells the user what an object does, not how. (Key point: Abstraction meaning)

2. Which is an example of abstraction?
   A. Making every member public
   B. Writing two functions with the same name
   C. A Stack offering push() and pop() while array and index stay hidden
   D. Using goto
   Answer: C. The user uses the interface without knowing the internals. (Key point: Example)

3. How do abstraction and encapsulation differ in level?
   A. Abstraction is implementation level; encapsulation is design level
   B. Both are run-time concepts
   C. They are identical
   D. Abstraction is design level (what to show); encapsulation is implementation level (how to hide)
   Answer: D. The comparison table gives this difference. (Key point: Level difference)

4. What is the relationship stated between them in C++?
   A. Encapsulation is the mechanism that makes abstraction possible
   B. Abstraction is the mechanism that makes encapsulation possible
   C. They are unrelated
   D. Abstraction replaces encapsulation
   Answer: A. The answer concludes encapsulation enables abstraction. (Key point: Relationship)

## Related in Object Oriented Programming

- [C versus C++ and C++ features](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Ac-vs-cpp-features) — Object Oriented Programming, chapter 2
- [Distance class relational operators](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adistance-relational-overload) — Object Oriented Programming, chapter 5

## Related in other subjects

- [Encapsulation and abstraction working together](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aencapsulation-abstraction-together) — Object Oriented Analysis and Design, chapter 1
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [ADT versus data structure](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aadt-vs-data-structure) — Data Structure and Algorithm, chapter 1
- [Data versus signal](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Adata-vs-signal) — Data Communication, chapter 1
