Abstraction and encapsulation are fundamental principles that underlie the…
2017
Abstraction and encapsulation are fundamental principles that underlie the object oriented approach to software development. What can you say about the following two statements ?
I. Abstraction allows us to focus on what something does without considering the complexities of how it works.
II. Encapsulation allows us to consider complex ideas while ignoring irrelevant detail that would confuse us.
- A.
Neither I nor II is correct.
- B.
Both I and II are correct.
- C.
Only II is correct.
- D.
Only I is correct.
Attempted by 339 students.
Show answer & explanation
Correct answer: D
Answer: Only the first statement is correct.
Explanation:
The first statement correctly describes abstraction: it allows us to focus on what something does without needing to consider the internal complexities of how it works.
Abstraction — separate the essential behavior from the implementation details so you can use or reason about a feature without seeing how it is implemented.
Encapsulation — bundle data and the operations on that data together and restrict direct access to an object's internals through controlled interfaces or access modifiers.
The second statement is incorrect because it describes ignoring irrelevant details to avoid confusion, which is a property of abstraction. Encapsulation is about grouping and protecting an object's internal state and exposing a controlled interface.