Chapter Test
Chapter Test
Question 1
1. Instructions only ✓
2. Instructions and data
3. Data only
4. None of these
Explanation
Question 2
1. Top-down approach ✓
2. Top-down and bottom-up approach
3. Bottom-up approach
4. None of these
Explanation
In Top-down approach, we first list down the main steps involved in solving a problem.
After that we break up each of those steps into their sub-steps and so on. This is similar
to Procedure Oriented Programming where we first write a main function and then call
sub-functions from the main function to perform each of these steps.
Question 3
1. Top-down approach
2. Top-down and bottom-up approach
3. Bottom-up approach ✓
4. None of these
Explanation
In Bottom-up approach to programming, the smallest individual parts of the system are
first identified and specified in detail. These individual parts are then linked together to
form larger and larger components until the entire program is ready. Object Oriented
Programming follows bottom-up approach because in OOP we first identify the
smallest parts of the program i.e. the objects. We then combine these objects to develop
the complete program.
Question 4
1. Interface
2. Instance ✓
3. Alias
4. Member
Explanation
Question 5
Objects that share the same attributes and behaviour are grouped together into a/an ...........
1. Interface
2. Instance
3. Alias
4. 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 6
........... is the technique of binding both data and functions together to keep them safe from
unauthorised access and misuse.
1. Abstraction
2. Inheritance
3. Encapsulation ✓
4. Polymorphism
Explanation
Question 7
........... refers to the act of representing essential features without including the background
details.
1. Abstraction ✓
2. Inheritance
3. Encapsulation
4. Polymorphism
Explanation
Question 8
........... is the feature by means of which one class acquires the properties of another class.
1. Abstraction
2. Inheritance ✓
3. Encapsulation
4. Polymorphism
Explanation
Question 9
1. Abstraction
2. Inheritance
3. Encapsulation
4. Polymorphism ✓
Explanation
Question 10
Explanation
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Question 8
Inheritance allows a class to acquire the properties of another class.
True
Question 9
Question 10
Objects from the same class do not share the same definition of attributes and behaviours.
False
Assignment Questions
Question 1
Answer
What are programming paradigms? Briefly explain two popular programming paradigms.
Answer
Question 3
Answer
Question 4
Answer
Question 5
Answer
Question 6
Answer
The world around us is made up of objects such as people, vehicles, buildings, streets,
mobiles, television, etc. Each of these objects has the ability to perform specific actions and
each of these actions influences the other objects in some way or the other. The objects
around us can be divided into the following categories:
1. Tangible Objects — These are the objects that we can see and touch. For example,
chair, pen, book, door, etc.
Question 7
Answer
Question 8
Answer
1. The size of the programs created using this approach may become larger than the
programs written using procedure-oriented programming approach.
2. Software developed using this approach requires a substantial amount of pre-work
and planning.
3. OOP code is difficult to understand if you do not have the corresponding class
documentation.
4. In certain scenarios, these programs can consume a large amount of memory.
Question 9
Answer
Abstraction refers to the act of representing essential features without including the
background details. For example, a building can be viewed as a single component (e.g.,
hospital) rather than separate components like cement, bricks, and rods. Abstraction is
relative to the perspective of the viewer.
Question 10
Differentiate between the Owner's and the Vet's perspective in Figure 1.24
Answer
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 11
Differentiate between the Car Mechanic's and Car Driver's perspective in Figure 1.25
Answer
From the viewpoint of the driver, a car is one single object. It can be operated using gears,
indicators, accelerator, brake, etc. The driver doesn't need to know or understand the internal
mechanisms of how these components actually work. From the viewpoint of the mechanic, it
is important for him to understand how the internal mechanisms like gears, indicators,
accelerator, brake, etc. actually work so that they can identify and fix issues with the cars. For
a mechanic, each car part is a single object.
Question 12
Answer
Encapsulation is a mechanism that binds together code and the data it manipulates. It keeps
them both safe from the outside world, preventing any unauthorised access or misuse. Only
member methods, which are wrapped inside the class, can access the data and other methods.
For example, an ATM contains different denominations of currency notes and it provides a
set operations to the user to withdraw money. The different denominations of currency notes
is the data, the set of operations are the methods and the ATM encapsulates them into a single
unit enabling us to withdraw cash conveniently.
Question 13
Answer
To explain Inheritance, let's take the example of traffic on the road. This traffic has some
commonalities. It consists of things that can move on the road and transport people and goods
from one place to another. We call these things vehicles. These vehicles differ from each
other in certain aspects like whether it transports passengers or goods, how many passengers
it can accommodate at a time, whether it is a two-wheeler or four-wheeler, etc. So, we have
different types of vehicles like Cars, Bikes, Scooters, Auto rickshaw, Buses, Trucks, etc. We
can represent this traffic using Inheritance as shown below. Here, Vehicle is the base class
having the common characteristics and behaviours of all Vehicles. Then we have Car, Bike,
Bus, Truck as subclasses of Vehicles.
Question 14
Polymorphism means different forms. Explain Polymorphism in Java and provide examples
to support your answer.
Answer
Question 15
Answer
Question 16
Explain the difference between Inheritance and Encapsulation with suitable examples.
Answer
Encapsulation is a mechanism that binds together code and the data it manipulates whereas
Inheritance is the mechanism by which a class acquires the properties and methods of another
class. An ATM binding together the different denominations of currency notes and all the
operations required to withdraw cash is an example of Encapsulation. Classifying Vehicles as
Car, Bike, Bus, Truck, etc. is an example of Inheritance.
Question 17
Answer
Interaction with program is via direct Interaction with program is via functions defined in
function calls. the class only.
Real world is represented by 'procedures' Real world is represented by objects and the
operating on data. operations that can be performed on these objects.
Data security is less as it contains lesser It is more secure as one of its primary features
features to protect the data. include data hiding.
A function can access any other function's Only the data whose access has been granted can be
data by calling that function. accessed by another function.
Limited and difficult code reusability. Versatile and easy code reusability.
Some examples of Procedural Programming Some examples of Object Oriented languages are
languages are C, COBOL, Pascal. C++, Java, C#.