Multiple Choice Questions
An object has ...........
- All of these ✓
An object is an identifiable entity that has a set of attributes, behaviour and state. So all of the options are applicable for objects.
A class is ...........
- An object factory
- A blueprint to create objects
- A specification for objects
- All of these ✓
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.
........... represents an entity in the real-world with its identity and behaviour.
- A class
- An object ✓
- A procedure
- A method
An object is an identifiable entity with a set of attributes, behaviour and state.
........... is a template to create similar objects that share common characteristics and behaviour.
- A function
- A procedure
- An attribute
- A class ✓
A class is a template or blueprint for multiple objects with similar features and maybe regarded as a specification for creating similar objects.
The values of an object's ........... represent the state of the object.
- Attributes ✓
Attributes of an object define its state.
The terms object and ........... are often interchangeable.
- Instance ✓
The terms object and instance are often interchangeable.
State whether the given statements are True or False
A class is a specification about the object.
Only one instance can be created from a single class.
A class is a user-defined data type.
Real world objects encapsulate state and behaviour.
There can be multiple abstraction of the same entity.
Objects interact with each other through messages.
What are objects? Give five examples.
Objects are identifiable entities that have a set of attributes, behaviour and state. Five examples of objects are car, pen, mobile, email, bank account.
Explain the anatomy of an object.
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.
Explain the following statement — "Class is a specification for objects".
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.
Explain the following statement — "Abstraction is relative to the perspective of the viewer".
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.
Identify five possible attributes and three possible behaviours of the following entities:
|Address||School gets over|
|Board||School conducts exams|
|Number of Students|
|Number of Teachers|
|School Name||Conduct Tests|
|Subject||Maintain discipline in class|
|Size||Watch Programmes(Movies, News, Cartoons, etc.)|
f. Washing Machine
Explain in detail how a class is different from an object.
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.
Give the reason why a class is known as:
i. An object factory
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
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
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
will create a parrot object belonging to the Bird class.
How are classes and objects inter-related? Support your answer with an example.
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:
|Registration Number||Stop car|
We can create two objects of this class to represent a red i20 car and a white Baleno car as shown below:
|Model||Start car||Model: i20|
|Registration Number||Stop car||Registration Number: KA 01 AA 1234|
|Colour||Apply break||Colour: Red|
|Model||Start car||Model: Baleno|
|Registration Number||Stop car||Registration Number: WB 01 AZ 6789|
|Colour||Apply break||Colour: White|
What do you understand by the term objects encapsulate state and behaviour?
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.
Explain how objects communicate with each other?
Objects communicate with each other by sending messages. The sender object requests the receiver object to perform an action.