Test Series - oops

Test Number 37/78

Q: Which feature is exhibited by the inbuilt classes?
A. Code reusability
B. Code efficiency
C. Code readability
D. Code reusability, efficiency and readability
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: Which among the following is the most abstract form of class?
A. Cars
B. BMW cars
C. Big cars
D. Small cars
Solution: 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.
Q: Which among the following best describes the Inheritance?
A. Copying the code already written
B. Using the code already written once
C. Using already defined functions in programming language
D. Using the data and functions into derived segment
Solution: It can only be indicated by using the data and functions that we use in derived class, being provided by parent class. Copying code is nowhere similar to this concept, also using the code already written is same as copying. Using already defined functions is not inheritance as we are not adding any of our own features.
Q: Which among the following best defines single level inheritance?
A. A class inheriting a derived class
B. A class inheriting a base class
C. A class inheriting a nested class
D. A class which gets inherited by 2 classes
Solution: A class inheriting a base class defines single level inheritance. Inheriting an already derived class makes it multilevel inheritance. And if base class is inherited by 2 other classes, it is multiple inheritance.
Q: Which among the following is correct for multiple inheritance?
A. class student{public: int marks;}s; class stream{int total;}; class topper:public student, public stream{ };
B. class student{int marks;}; class stream{ }; class topper: public student{ };
C. class student{int marks;}; class stream:public student{ };
D. class student{ }; class stream{ }; class topper{ };
Solution: Class topper is getting derived from 2 other classes and hence it is multiple inheritance. Topper inherits class stream and class student publicly and hence can use its features. If only few classes are defined, there we are not even using inheritance (as in option class student{ }; class stream{ }; class topper{ };).
Q: Which programming language doesn’t support multiple inheritance?
A. C++ and Java
B. C and C++
C. Java and SmallTalk
D. Java
Solution: Java doesn’t support multiple inheritance. But that feature can be implemented by using the interfaces concept. Multiple inheritance is not supported because of diamond problem and similar issues.
Q: Which among the following is correct for a hierarchical inheritance?
A. Two base classes can be used to be derived into one single class
B. Two or more classes can be derived into one class
C. One base class can be derived into other two derived classes or more
D. One base class can be derived into only 2 classes
Solution: One base class can be derived into the other two derived classes or more. If only one class gets derived by only 2 other classes, it is also hierarchical inheritance, but it is not a mandatory condition, because any number of derived classes can be there.

You Have Score    /10