212 Classes and objects
What is the role of a class in object-oriented programming?
Show solution
A class acts as a template or blueprint that defines what an object will look like and how it will behave when created. It specifies the structure and features shared by all objects of that class.
How is an object related to a class?
Show solution
An object is an instance created from a class. While the class defines the shared structure and behaviour, each object can have its own attribute values but follows the design of the class.
In the cupcake analogy, what represents the class and what represents the objects?
Show solution
The cupcake wrapper represents the class — it defines the shape and structure of the cupcakes. The individual cupcakes made using the wrapper represent the objects — they can have different flavours and decorations but share the same shape.
Give an example from everyday life that shows the relationship between a class and an object.
Show solution
One example is a blueprint for a house (class) and the actual house built from that blueprint (object). The blueprint defines the design, while each house built can have its own colours or interior features.
How do the attributes of objects created from the same class vary?
Last updated
Was this helpful?