ITPEC FE Morning October 2020 Question 46

Which of the following is an appropriate relation between a class and an instance in object-oriented programming?

Explanation

An instance is created from the definition in a class — the class is the blueprint, the instance a concrete object built from it.

A class defines the attributes and methods shared by one kind of object. Instantiating the class, for example with new, creates an object that holds its own attribute values and behaves as the class defines. The same class can be instantiated any number of times, and each instance belongs to the class it was created from.

Answer (b)

Why not others:

  • •(a) — reverses the roles: the class defines the specification, and each instance follows it
  • •(c) — an instance is created from the definition of one class; the one-to-many relation runs the other way, many instances per class
  • •(d) — one class normally yields many instances; allowing only one is a special design choice (the Singleton pattern), not the general relation

Key rule: Class is to instance as blueprint is to building: one definition, any number of objects, each with its own attribute values.

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.