ITPEC FE Morning April 2019 Question 47

Which of the following is an explanation of encapsulation in object orientation?

Explanation

Bundling data with its procedures in one object and hiding them from outside — that is encapsulation.

An object holds its data (attributes) together with the procedures (methods) that operate on them. Outside code may use the object only through its public methods; the data and the implementation stay hidden (information hiding). The internals can then change without affecting the users of the object, and the data cannot be put into an invalid state from outside.

Answer (b)

Why not others:

  • •(a) — grouping objects of the same nature into an abstraction is classification, which yields a class
  • •(c) — extracting what several classes share into a base class is generalization
  • •(d) — a subclass taking over the nature of its base class is inheritance

Key rule: Encapsulation is about what an object shows to the outside; generalization and inheritance are about how classes relate to each other.

System Development Technology · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.