This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “Class Use”.
d) Object creation
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?
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
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
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?
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.
a) Functions are restricted
b) Functions can’t be defined
c) Functions can also be encapsulated
d) Functions can have more security
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 follow is a feature of class?
a) Object orientation
b) Procedure orientation
c) Both object and procedure orientation
d) Neither object nor procedure orientation
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 feature of OOP.
8. Class is _____________ of an object.
a) Basic function definition
b) Detailed description with values
d) Set of constant values
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 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
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
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
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.
a) To design a user intended code
b) To model real world objects
c) To design the interfaces
d) To model the functions
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
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
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?
b) BMW cars
c) Big cars
d) Small cars
Explanation: The most abstract class is class Cars. The class Cars is most general form of all other cars. If it is a brand of car, it comes under car. If it is 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), here is complete set of 1000+ Multiple Choice Questions and Answers.