This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “Abstraction”.
1. Which among the following best defines abstraction?
a) Hiding the implementation
b) Showing the important data
c) Hiding the important data
d) Hiding the implementation and showing only the features
Explanation: It includes hiding the implementation part and showing only the required data and features to the user. It is done to hide the implementation complexity and details from the user. And to provide a good interface in programming.
2. Hiding the implementation complexity can:
a) Make the programming easy
b) Make the programming complex
c) Provide more number of features
d) Provide better features
Explanation: It can make the programming easy. The programming need not know how the inbuilt functions are working but can use those complex functions directly in the program. It doesn’t provide more number of features or better features.
3. Class is _________ abstraction
Explanation: Class is logical abstraction because it provides a logical structure for all of its objects. It gives an overview of the features of an object.
4. Object is ________ abstraction
Explanation: Object is real abstraction because it actually contains those features of class. It is the implementation of overview given by class. Hence the class is logical abstraction and its object is real.
5. Abstraction gives higher degree of ________
a) Class usage
b) Program complexity
c) Idealized interface
d) Unstable interface
Explanation: It is to idealize the interface. In this way the programmer can use the programming features more efficiently and can code better. It can’t increase the program complexity, as the feature itself is made to hide it.
6. Abstraction can apply to:
a) Control and data
b) Only data
c) Only control
Explanation: Abstraction applies to both. Control abstraction involves use of subroutines and control flow abstraction. Data abstraction involves handling pieces of data in meaningful ways.
7. Which among the following can be viewed as combination of abstraction of data and code.
Explanation: Object can be viewed as abstraction of data and code. It uses data members and their functioning as data abstraction. Code abstraction as use of object of inbuilt class.
8. Abstraction principle includes___________
a) Use abstraction at its minimum
b) Use abstraction to avoid longer codes
c) Use abstraction whenever possible to avoid duplication
d) Use abstraction whenever possible to achieve OOP
Explanation: Abstraction principle includes use of abstraction to avoid duplication (usually of code). It this way the program doesn’t contain any redundant functions and make the program efficient.
9. Higher the level of abstraction, higher are the details.
Explanation: Higher the level of abstraction, lower are the details. The best way to understand this is to consider a whole system that is highest level of abstraction as it hides everything inside. And next lower level would contain few of the computer components and so on.
10. Encapsulation and abstraction differ as:
a) Binding and Hiding respectively
b) Hiding and Binding respectively
c) Can be used any way
d) Hiding and hiding respectively
Explanation: Abstraction is hiding the complex code. For example we directly use cout object in C++ but we don’t know how is it actually implemented. Encapsulation is data binding, as in, we try to combine the similar type of data and functions together.
11. In terms of stream and files________
a) Abstraction is called a stream and device is called a file
b) Abstraction is called a file and device is called a stream
c) Abstraction can be called both file and stream
d) Abstraction can’t be defined in terms of files and stream
Explanation: Abstraction is called stream to provide a level of complexity hiding, for how the files operations are actually done. Actual devices are called file because in one way or another, those can be considered as single entity and there is nothing hidden.
12. If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?
a) Using private access specifier for data members
b) Using class concept with both data members and member functions
c) Using public member functions to access and manipulate the data members
d) Data is not sufficient to decide what is being used
Explanation: It is the concept of hiding program complexity and actual working in background. Hence use of public member functions illustrates abstraction here.
13. A phone is made up of many components like motherboard, camera, sensors and etc. If the processor represents all the functioning of phone, display shows the display only, and the phone is represented as a whole. Which among the following have highest level of abstraction?
Explanation: Phone as a whole have the highest level of abstraction. This is because the phone being a single unit represents the whole system. Whereas motherboard, display and camera are its components.
14. Which among the following is not a level of abstraction:
a) Logical level
b) Physical level
c) View level
d) External level
Explanation: Abstraction is generally divided into 3 different levels, namely, logical, physical and view level. External level is not defined in terms of abstraction.
15. Using higher degree of abstraction __________
a) May get unsafe
b) May reduce readability
c) Can be safer
d) Can increase vulnerability
Explanation: It will make the code safer. One may think it reduces the readability, but the fact is, it actually helps us understand the code better. We don’t have to read the complex code which is of no use in understanding the program.
Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+ Multiple Choice Questions and Answers.