KnowledgeBoat Logo

Computer Applications

How are classes and objects inter-related? Support your answer with an example.

OOP Intro Java

37 Likes

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:

AttributesBehaviours
ModelStart car
Registration NumberStop car
ColourApply break

We can create two objects of this class to represent a red i20 car and a white Baleno car as shown below:

AttributesBehavioursState
ModelStart carModel: i20
Registration NumberStop carRegistration Number: KA 01 AA 1234
ColourApply breakColour: Red
AttributesBehavioursState
ModelStart carModel: Baleno
Registration NumberStop carRegistration Number: WB 01 AZ 6789
ColourApply breakColour: White

Answered By

17 Likes


Related Questions