Multiple Choice Questions
In object oriented programming, the stress is given on:
Reason — In Object Oriented Programming, the stress is put on the data values rather than functions.
Which of the following principle does not allow to access directly from outside the class premises?
- data hiding
- all of the above
all of the above
Reason — Data hiding, Encapsulation and Abstraction, all the three restrict direct access to data from outside a class.
The process of combining data and functions that enables them to be together as a single entity is called
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.
The process by which a class acquires the properties from another class is called:
Reason — Inheritance is a property by virtue of which one class acquires some features from another class.
In procedural programming, the stress is laid on:
Reason — A programming language in which emphasis is given on the functions rather than data values is known as Procedure Oriented Programming Language.
Which of the following is a blue print that creates objects of similar types?
Reason — Class is a blue print that creates objects of similar types.
Which of the following is not an object oriented programming language?
Reason — BASIC is a procedure oriented programming language.
The process of restricting the free flow of data from the outside world is known as:
Reason — The process of restricting the free flow of data from the outside world is known as encapsulation.
Which of the following is true for Polymorphism?
- Uses same function for different operations
- Uses same operation for different functions
- It is not a principle of oop
- It uses reusability feature.
Uses same function for different operations
Reason — Polymorphism is the process of using a function for carrying multiple operations.
In procedure oriented programming, the stress is given on:
Reason — In procedure oriented programming, the stress is given on function or procedure.
Fill in the blanks
Object is the fundamental concept in object oriented programming language.
Objects can communicate with each other through function in object oriented programming language.
Using a function for multiple operations is called as polymorphism.
Data Abstraction is an act of representing essential features without including background details.
Feature of wrapping data and functions as a single unit is called encapsulation.
Inheritance promotes the reusability feature, in object oriented programming.
Data hiding confirms the security of data members from being manipulated from unauthorized access.
In encapsulation, data can be public or private whereas, in data hiding, data must be private only.
Write short answers
What is object oriented programming? Name two object oriented programming languages.
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.
Name four basic principles of object oriented programming.
Four basic principles of object oriented programming are:
Why do we prefer object oriented approach in complex programming? Explain.
Object Oriented approach offers advantages like:
- Data Values are secured.
- Mishandling of data is protected.
- Error detection and correction becomes easier.
- Easier in coding complex programs.
For these reasons, Object Oriented approach is preferred for complex programming.
What is meant by a base class and a derived class?
The class that is inherited is known as base class and the class that inherits from the base is known as derived class.
Mention two limitations of procedure oriented programming approach.
Two limitations of procedure oriented programming approach are:
- No restriction on data values.
- No reusability concept hence time management, testing and length of the program increases.
What is meant by Encapsulation?
Wrapping of data and functions of an object as a unit that can be used together in a specific operation is called Encapsulation.
Define the following with an example each.
(a) 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:
(b) 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.
In what way is Data Hiding related to Data Abstraction?
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.
Give an example to explain Data Abstraction.
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.
What is meant by Data Hiding?
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.
Give two differences between Data Hiding and Encapsulation.
Two differences between Data Hiding and Encapsulation are as follows:
- Data hiding focuses more on data security whereas, encapsulation focuses more on hiding the complexity of the system.
- Data hiding focuses on restricting the use of data whereas, encapsulation deals with wrapping of data and functions.
'Encapsulation reduces the complexity and makes the system easier'. Explain this statement with a real world example.
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.
Give two differences between Procedure Oriented languages and Object Oriented languages.
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 functions and procedures rather than data.||Object Oriented languages lay emphasis on data rather than functions.|
|Limited and difficult code reusability leading to lengthy programs which are difficult to debug and maintain.||Versatile and easy code reusability leading to simpler programs which are easier to debug and maintain.|
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.
(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.