CH.
1 : Introduction to Object-Oriented Programming concepts
Q. 1. Fill in the blanks:
1. Which of the following is true for Polymorphism?
Answer
Uses same function for different operations
Reason — Polymorphism is the process of using a function for carrying multiple operations.
2. In procedure oriented programming, the stress is given on:
Answer
Function
Reason — In procedure oriented programming, the stress is given on function or procedure.
3. Which of the following principle does not allow to access directly from outside the class premises?
Answer
all of the above
Reason — Data hiding, Encapsulation and Abstraction, all the three restrict direct access to data from outside
a class.
4. The process of combining data and functions that enables them to be together as a single entity is
called
Answer
Encapsulation
Reason — Wrapping of data and functions of an object as a unit that can be used together in a specific
operation is known as Encapsulation.
5. The process by which a class acquires the properties from another class is called:
Answer
Inheritance
Reason — Inheritance is a property by virtue of which one class acquires some features from another class.
6. In procedural programming, the stress is laid on:
Answer
Function
Reason — A programming language in which emphasis is given on the functions rather than data values is
known as Procedure Oriented Programming Language.
7. Which of the following is a blue print that creates objects of similar types?
Answer
class
Reason — Class is a blue print that creates objects of similar types.
8. Which of the following is not an object oriented programming language?
Answer
BASIC
Reason — BASIC is a procedure oriented programming language.
9. The process of restricting the free flow of data from the outside world is known as:
Answer
encapsulation
Reason — The process of restricting the free flow of data from the outside world is known as encapsulation.
Q.2 Fill in the blanks:
1. Object is the fundamental concept in object oriented programming language.
2. Objects can communicate with each other through Function in object oriented programming language.
3. Using a function for multiple operations is called as polymorphism.
4. Data Abstraction is an act of representing essential features without including background details.
5. Feature of wrapping Data and Function as a single unit is called encapsulation.
6. Inheritance promotes the reusability feature, in object oriented programming.
7. Data hiding confirms the security of data members from being manipulated from unauthorized access.
8. In encapsulation, data can be Public or Private whereas, in data hiding, data must be Private only.
Q.3 Answer in one sentence:
1. What is object oriented programming? Name two object oriented programming languages.
Answer
Object Oriented Programming is an approach in which stress is laid on data rather than functions. The data
values remain associated with the functions of a particular block of the program so as to encourage data
security. Two Object Oriented Programming languages are C++ and Java.
2. Name four basic principles of object oriented programming.
Answer
Four basic principles of object oriented programming are:
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism
3. Why do we prefer object oriented approach in complex programming? Explain.
Object Oriented approach offers advantages like:
1. Data Values are secured.
2. Mishandling of data is protected.
3. Error detection and correction becomes easier.
4. Easier in coding complex programs.
For these reasons, Object Oriented approach is preferred for complex programming.
4. What is meant by a base class and a derived class?
Answer
The class that is inherited is known as base class and the class that inherits from the base is known as derived
class.
5. Mention two limitations of procedure oriented programming approach.
Answer
Two limitations of procedure oriented programming approach are:
1. No restriction on data values.
2. Limited and difficult code reusability.
6. What is meant by Encapsulation?
Answer
Wrapping of data and functions that operate on that data into a single unit is called Encapsulation.
Q.4 Define the following with example each:
1. Inheritance
Answer
Inheritance is a property by virtue of which one class acquires some features from another class. It promotes
reusability.
As an example of inheritance, we can consider the case of vehicles. All vehicles have some common features
like they can move on the road and transport people and goods from one place to another. 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. Using inheritance, we can make
vehicles the base class with the different types of vehicles being the derived class as shown below:
2. Polymorphism
Answer
Polymorphism is the process of using a function for carrying multiple operations. During this process, an object
may include a function for multiple operations.
As an example, if we ask different animals to speak, they respond in their own way. Dog will bark, duck will
quack, cat will say meow and so on. So, the same action of speaking is performed in different ways by different
animals. This is the concept of Polymorphism.
3. In what way is Data Hiding related to Data Abstraction?
Answer
Data Hiding and Data Abstraction are complementary concepts. Data Abstraction focuses on the observable
behaviour of an object, whereas Data hiding or Data Encapsulation focuses upon the implementation that
gives rise to this behaviour. In other words, Data Abstraction cares about what something does but not how it
does it. Data Encapsulation cares about how something does what it does such that others don't have to worry
about the implementation details. Hence, we can say that Encapsulation is a way to implement Data
Abstraction.
4. Give an example to explain Data Abstraction.
Answer
Data abstraction is an act of representing the essential features without knowing the background details.
As an example, lets consider the electrical switchboard. Switchboard provides us a very simple way to switch
ON/OFF lights, fans and other electrical appliances. It hides all the details like the internal wiring of the house,
how the switch is turning the light ON/OFF, etc.
5. What is meant by Data Hiding?
Answer
The insulation of data that does not allow it to be accessed directly outside the class premises, although it is
available in the same program is known as Data Hiding.
6. Give two differences between Data Hiding and Encapsulation.
Answer
Two differences between Data Hiding and Encapsulation are as follows:
1. Data hiding focuses more on data security whereas, encapsulation focuses more on hiding the
complexity of the system.
2. Data hiding focuses on restricting the use of data whereas, encapsulation deals with wrapping of data
and functions.
7. 'Encapsulation reduces the complexity and makes the system easier'. Explain this statement with a
real world example.
Answer
Encapsulation means wrapping of data and methods into a single unit and restricting direct access to some of
the object's components.
Let us take the example of an ATM machine. When we want to withdraw money from an ATM machine, we
swipe our card, enter the pin and then enter the amount of money we want to withdraw. The ATM machine
processes our request and gives us the required money.
Here, money is treated as data and the various processes such as verification of the authenticity of the user,
pin and balance in the account etc., are the methods. The data and methods are encapsulated in the ATM
(which is treated as a class). Since the user doesn't have to understand the actual working of the ATM
machine, encapsulation reduces the complexity and makes the system (ATM machine) easier to use.
8. Give two differences between Procedure Oriented languages and Object Oriented languages.
Answer
Two differences between Procedure Oriented languages and Object Oriented languages are as follows:
Procedure Oriented languages Object Oriented languages
Procedure Oriented languages lay emphasis on Object Oriented languages lay emphasis on data
functions and procedures rather than data. rather than functions.
Limited and difficult code reusability leading to Versatile and easy code reusability leading to
lengthy programs which are difficult to debug and simpler programs which are easier to debug and
maintain. maintain.
9. Which of the Object Oriented programming principles explain the following illustrations? Justify.
(a) The variables and methods are put together in a Class.
(b) A man withdrawing money from ATM.
Answer
(a) Encapsulation is illustrated in the given picture. Wrapping of data and functions of an object as a unit
(class) that can be used together in a specific operation is known as Encapsulation. In the picture, the
variables and methods are being encapsulated in a class.
(b) The principle of Data abstraction is illustrated here as the man withdraws money from the ATM using the
withdraw option. He knows the essential features of the ATM machine such as withdrawing money, without
knowing the complex background details of how the ATM machine is operating to provide money to him.