What accurately characterises the purpose of a class in object-oriented…
2025
What accurately characterises the purpose of a class in object-oriented programming?
- A.
A container used exclusively for holding basic data types
- B.
A template used to define properties and behaviours of objects
- C.
A sequence of instructions designed to execute a specific operation
- D.
A storage location that holds the reference to an object instance
Attempted by 129 students.
Show answer & explanation
Correct answer: B
In object-oriented programming (OOP), a class is accurately characterized as a blueprint, template, or user-defined data type used to create specific instances called objects.
Note (For More Understanding)
It defines the structure and behavior that its objects will possess by grouping two core elements together:
Attributes (Data/Properties): Represented by variables, these define the state or characteristics of the object.
Methods (Functions/Behaviors): These define the actions or operations that the object can perform.
Core Characteristics of a Class
Abstraction and Encapsulation: A class acts as a protective container that binds data and the methods that manipulate that data together, often hiding internal implementation details from the outside world.
No Memory Allocation: A class itself is a logical construct. Defining a class does not allocate physical memory (RAM) for its attributes; memory is only allocated when an object of that class is instantiated.
Reusability: Once a class is written and tested, it can be used to generate an infinite number of unique objects, each maintaining its own independent state while sharing the same structure.
A Simple Analogy
Think of a class as a blueprint for a house. The blueprint itself isn't a house—you can't live in it, and it takes up no real-world plot space. However, it explicitly describes where the walls go and how the plumbing works. When a builder uses that blueprint to construct physical structures, those structures are the objects (or instances). You can build five houses from the same blueprint; they will all share the same design, but each can have a different family living inside and a different colored front door.