ITPEC FE Morning April 2021 Question 47

Which of the following is an appropriate relationship between classes and instances in object orientation?

Explanation

An instance is created from the definition of a class — the class is the template, and each instance is a concrete object built from it.

A class defines the attributes (data) and methods (operations) that its objects will have. Creating an instance allocates an object with its own values for those attributes, and it behaves as the class's methods describe. One class can produce any number of instances, and each instance is created from one class.

Answer (b)

Why not others:

  • •(a) — reverses the roles: the class defines the specification, and instances follow it
  • •(c) — reverses the multiplicity: the relation is one class to many instances, and an instance is created from a single class
  • •(d) — a class normally has many instances; limiting it to one is a special design choice, the Singleton pattern, not the general rule

Key rule: Class to instance is one-to-many, like a blueprint and the houses built from it: the class holds the definition, each instance holds its own data.

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.