Object Oriented Programming using C++ Questions and Answers – Class Use

This set of Object Oriented Programming (OOPs) using C++ Multiple Choice Questions & Answers (MCQs) focuses on “Class Use”.

1. Which among the following is the main characteristic of class?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Object creation
View Answer

Answer: b
Explanation: The classes are made to encapsulate the data and properties that are most similar and can be grouped together inside a single class. This single class can represent all of those features by creating its instances.

2. To group all the brands of cars, what should be used?
a) Class
b) Structure
c) Function
d) Object
View Answer

Answer: a
Explanation: A class can be used to group all the brands of cars. The Different brands may have different properties but all will have some common properties like number of wheels and doors, accessories etc. All of those properties can be grouped into a single class representing all the cars.

3. If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient if the programmer wants to implement multiplication too?
a) Define a public function which multiplies two numbers
b) Define a public function that returns values of two data members
c) Define a private function which multiplies two numbers
d) Define a private function that returns values of two data members
View Answer

Answer: b
Explanation: The best choice would be to define a public member function that returns the values of two data members of the class. This way we can implement any operation on those data members. Also there won’t be any need to modify the program and to add new functions for each new operation.

4. If a database have to be maintained using OOP, to store the details of each employee in a company, which would be the best choice among the following?
a) Define a class to store details of each employee
b) Define a structure to store details of each employee
c) Define separate variable for each detail
d) Define a generic type to store string and number details
View Answer

Answer: a
Explanation: A single class can be defined that represents a single employee of a company. The specific type of functions that can be applied to specific employees can be put into another class that is derived from the existing class.

5. Which class represents the most abstracted information?
a) Nested
b) Derived
c) Enclosed
d) Base
View Answer

Answer: d
Explanation: The base classes are the most abstracted part of information. A base class having many other derived classes would have a bigger overview of all the other derived classes. Hence the base classes have the most abstract information.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which among the following is an advantage of using classes over structures of C?
a) Functions are restricted
b) Functions can’t be defined
c) Functions can also be encapsulated
d) Functions can have more security
View Answer

Answer: c
Explanation: The functions are also made easy to be encapsulated inside a class. In structures, only the data members were allowed to be encapsulated. Hence classes can represent an entity in a better way.

7. Which among the following is a feature of class?
a) Object orientation
b) Procedure orientation
c) Both object and procedure orientation
d) Neither object nor procedure orientation
View Answer

Answer: a
Explanation: Thee use of classes feature the object oriented programming. The OOP concept can be implemented by using class and their objects. Procedures orientation is not a feature of OOP.

8. Class is _____________ of an object.
a) Basic function definition
b) Detailed description with values
c) Blueprint
d) Set of constant values
View Answer

Answer: c
Explanation: The class is an overview for an object. It contains the basic details map of data that an object will contain. An object is independent representation of class.

9. In which case the classes can be used to make the more efficient program?
a) To define a function that is called frequently in a program
b) To structure data that is most similar
c) To group the most similar data and operations
d) To define a blueprint that shows memory location of data
View Answer

Answer: c
Explanation: The classes would be more suitable to use in case where we need to group the most similar data and operations. The data can be represented as data members of class and operations as member functions of class. This is indirectly encapsulation feature.

10. What is the use of inbuilt classes?
a) Provide predefined data
b) Provide predefined functions
c) Provide predefined data and functions
d) Provide predeclared data to be overridden
View Answer

Answer: c
Explanation: The data that is constant or is always the same initially for use can be provided by some inbuilt classes. The functions that are mostly used are also provided by the inbuilt classes. The data and functions can be used by including the corresponding header file or library.

11. Which feature is exhibited by the inbuilt classes?
a) Code reusability
b) Code efficiency
c) Code readability
d) Code reusability, efficiency and readability
View Answer

Answer: d
Explanation: The code is reusable as the functions which are already written, can be used anytime required. The code becomes easier to read. Also, the code is efficient as there is no need to assign any external code.

12. Why do we use user defined classes?
a) To design a user intended code
b) To model real world objects
c) To design the interfaces
d) To model the functions
View Answer

Answer: b
Explanation: The primitive classes are not sufficient for the programming complex algorithms. Some user defined classes are required to represent a real world object and to define a blueprint of what the class should actually contain. The user defined classes are as per the requirements and need of user.

13. Why do classes use accessor methods?
a) To make public data accessible to client
b) To make public data private to client
c) To make private data public for whole program
d) To make private data accessible to the client
View Answer

Answer: d
Explanation: The private data of a class is usually not accessible. But the data can be accessed by the user using accessor functions. These functions allows the user to get the data stored as private in a class.

14. Why do classes use mutator methods?
a) Allows client to modify the program
b) Allows client to modify/write the private members
c) Allows servers to access all the private data
d) Allows servers to access only protected members
View Answer

Answer: b
Explanation: The client can have rights to access a file and write something to it. This is mandatory to keep the private data updated. Also it is an advantage over the use of hidden class members.

15. Which among the following is the most abstract form of class?
a) Cars
b) BMW cars
c) Big cars
d) Small cars
View Answer

Answer: a
Explanation: The most abstract class is class Cars. The class Cars is the most general form of all other cars. If it is a brand of car, it comes under car. If it is the type of car then also it comes under Cars.

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.