Multiple Choice Questions
Question 1
An object has ...........
- Attributes
- State
- Behaviour
- All of these ✓
Explanation
An object is an identifiable entity that has a set of attributes, behaviour and state. So all of the options are applicable for objects.
Question 2
A class is ...........
- An object factory
- A blueprint to create objects
- A specification for objects
- All of these ✓
Explanation
A class is a template or blueprint for multiple objects with similar features and maybe regarded as a specification for creating similar objects. So all of the options are applicable for class.
Question 3
........... represents an entity in the real-world with its identity and behaviour.
- A class
- An object ✓
- A procedure
- A method
Explanation
An object is an identifiable entity with a set of attributes, behaviour and state.
Question 4
........... is a template to create similar objects that share common characteristics and behaviour.
- A function
- A procedure
- An attribute
- A class ✓
Explanation
A class is a template or blueprint for multiple objects with similar features and maybe regarded as a specification for creating similar objects.
Question 5
The values of an object's ........... represent the state of the object.
- Methods
- Procedures
- Attributes ✓
- Classes
Explanation
Attributes of an object define its state.
Question 6
The terms object and ........... are often interchangeable.
- Instance ✓
- Behaviour
- Attribute
- State
Explanation
The terms object and instance are often interchangeable.
State whether the given statements are True or False
Question 1
A class is a specification about the object.
True
Question 2
Only one instance can be created from a single class.
False
Question 3
A class is a user-defined data type.
True
Question 4
Real world objects encapsulate state and behaviour.
True
Question 5
There can be multiple abstraction of the same entity.
True
Question 6
Objects interact with each other through messages.
True
Assignment Questions
Question 1
What are objects? Give five examples.
Answer
Objects are identifiable entities that have a set of attributes, behaviour and state. Five examples of objects are car, pen, mobile, email, bank account.
Question 2
Explain the anatomy of an object.
Answer
Objects are the basic units of an object oriented system. An object is an identifiable entity that has its own set of attributes, behaviour and state. Attributes are individual characteristics that differentiate one object from another. Behaviour is defined by the set of functions or operations an object can perform. State is defined by the set of values held by its attributes.
Question 3
Explain the following statement — "Class is a specification for objects".
Answer
As class describes the common attributes and behaviours of its objects in detail, hence we can say that a class is a specification for objects. It can be viewed as a template or blueprint for multiple objects with similar features.
Question 4
Explain the following statement — "Abstraction is relative to the perspective of the viewer".
Answer
It means that there can be different abstractions of an entity depending on the viewpoint of the user. Lets take the example of a pet dog. From the viewpoint of the dog's owner, the things that are essential for the dog are his favorite food, the colour of his food bowl, his favorite game that he enjoys playing with his owner, his preferred time for walk, etc. From the viewpoint of the dog's vet (doctor for animals), the important things about the dog are whether the dog's body functions are normal or not to ensure that the dog is healthy. Like this, there can be two abstractions for the dog — one for the dog's owner and the other for the dog's vet.
Question 5
Identify five possible attributes and three possible behaviours of the following entities:
a. School
Answer
Attributes | Behaviours |
---|---|
Name | School Starts |
Address | School gets over |
Board | School conducts exams |
Principal | |
Number of Students | |
Number of Teachers |
b. Student
Answer
Attributes | Behaviours |
---|---|
Name | Study |
Address | Play |
Class | Sleep |
Section | |
Roll No. |
c. Teacher
Answer
Attributes | Behaviours |
---|---|
Name | Teach Class |
School Name | Conduct Tests |
Subject | Maintain discipline in class |
Class | |
Address |
d. Computer
Answer
Attributes | Behaviours |
---|---|
Manufacturer | Start Computer |
Model | Shutdown Computer |
Processor | Run applications |
RAM | |
Hard Disk |
e. Television
Answer
Attributes | Behaviours |
---|---|
Manufacturer | Turn On |
Model | Turn OFF |
Size | Watch Programmes(Movies, News, Cartoons, etc.) |
Smart | |
Resolution |
f. Washing Machine
Answer
Attributes | Behaviours |
---|---|
Manufacturer | Start Wash |
Model | Stop Wash |
Capacity | Rinse |
Energy Rating | |
Noise Level |
g. Chair
Answer
Attributes | Behaviours |
---|---|
Material | Buy |
Colour | Sell |
Weight | Sit |
Revolving | Repair |
Price |
h. Person
Answer
Attributes | Behaviours |
---|---|
First Name | Eat |
Last Name | Sleep |
Age | Walk |
Gender | |
Address |
Question 6
Explain in detail how a class is different from an object.
Answer
The class is just a specification of the object. The attributes and methods in the class are thus declarations that do not contain any values. However, the object is a concrete instance of a class with properly defined values for each attribute and behaves as per the methods of the class.
Question 7
Give the reason why a class is known as:
i. An object factory
Answer
A class is called an object factory because objects are created from the class that contains common attributes and behaviour. The class behaves like a specification for creating such similar objects.
ii. A composite data type
Answer
A class is composed of member variables which are of different data types. Hence, a class can be viewed as a composite data type.
iii. A user-defined data type
Answer
The entire data and the code, contained in an object, becomes a user-defined data type using the concept of a class. The class may be considered as a data type and an object as a variable of that data type. For example, once the Bird class has been defined, the statement
Bird parrot;
will create a parrot object belonging to the Bird class.
Question 8
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 |
Question 9
What do you understand by the term objects encapsulate state and behaviour?
Answer
An object stores its state in member variables and exposes its behaviour through the member methods. The member methods operate on member variables and serve as the primary mechanism to interact with the object. Only the member methods which are wrapped inside the class can access the data and change its state. Hence, the state and behaviour are said to be encapsulated by the object, hiding internal state and requiring all interaction to be performed through the methods of the object.
Question 10
Explain how objects communicate with each other?
Answer
Objects communicate with each other by sending messages. The sender object requests the receiver object to perform an action.