Computer Applications
How are classes and objects inter-related? Support your answer with an example.
Answer
A Class is used to create various Objects that have different attributes and common behaviours. Each object follows all the features defined within a class. That is why class is also referred to as a blue print or prototype of an object. For example, a class representing a car will have the following characteristics and behaviours:
Attributes | Behaviours |
---|---|
Model | Start car |
Registration Number | Stop car |
Colour | Apply break |
We can create two objects of this class to represent a red i20 car and a white Baleno car as shown below:
Attributes | Behaviours | State |
---|---|---|
Model | Start car | Model: i20 |
Registration Number | Stop car | Registration Number: KA 01 AA 1234 |
Colour | Apply break | Colour: Red |
Attributes | Behaviours | State |
---|---|---|
Model | Start car | Model: Baleno |
Registration Number | Stop car | Registration Number: WB 01 AZ 6789 |
Colour | Apply break | Colour: White |