Test Series - oops

Test Number 41/78

Q: Which among the following best defines multilevel inheritance?
A. A class derived from another derived class
B. Classes being derived from other derived classes
C. Continuing single level inheritance
D. Class which have more than one parent
Solution: Only if the class is being derived from other derived class, it can be called as multilevel inheritance. If a class is derived from another class, it is single level inheritance. There must be more than one level of inheritance.
Q: If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class constructor will be called first if the object of E or D is created?
A. A
B. B
C. C
D. A and B
Solution: A is parent of all other classes indirectly. Since A is parent of B and B is parent of C and so on till E. Class A constructor will be called first always.
Q: If there are 3 classes. Class C is derived from class B and B is derived from A, Which class destructor will be called at last if object of C is destroyed.
A. A
B. B
C. C
D. All together
Solution: The destructors are called in the reverse order of the constructors being called. Hence in multilevel inheritance, the constructors are created from parent to child, which leads to destruction from child to parent. Hence class A destructor will be called at last.
Q: Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
A. Class at 1st level
B. Class 2nd last level
C. Class at 5th level
D. All with same abstraction
Solution: The class with highest degree of abstraction will be the class at the 1st level. You can look at a simple example like, a CAR is more abstract than SPORTS CAR class. The level of abstraction decrease with each level as more details comes out.
Q: If all the classes use private inheritance in multilevel inheritance then ______________
A. It will not be called multilevel inheritance
B. Each class can access only non-private members of its parent
C. Each subsequent class can access all members of previous level parent classes
D. None of the members will be available to any other class
Solution: The classes will be able to access only the non-private members of its parent class. The classes are using private inheritance, hence all the members of the parent class become private in the derived class. In turn those won’t be allowed for further inheritance or direct access outside the class.
Q: Multilevel inheritance allows _________________ in the program.
A. Only 7 levels of inheritance
B. At least 7 levels of inheritance
C. At most 16 levels of inheritance
D. As many levels of inheritance as required
Solution: The multilevel inheritance allows any number of levels of inheritance. This is the maximum flexibility feature to make the members available to all the new classes and to add their own functionalities. The code reusability is used too.
Q: What is the minimum number of levels for a implementing multilevel inheritance?
A. 1
B. 2
C. 3
D. 4
Solution: There must be at least 3 levels of inheritance. Otherwise if less, it will be single level inheritance or would have got no inheritance implemented. There must be a derived class from which another class is derived.
Q: In multilevel inheritance one class inherits _______________
A. Only one class
B. More than one class
C. At least one class
D. As many classes as required
Solution: The classes inherit only from one class. This continues as each class inherits only one class. There should not be any class that inherits from two or more classes or which have more than one subclass.
Q: Can abstract classes be used in multilevel inheritance?
A. Yes, always
B. Yes, only one abstract class
C. No, abstract class doesn’t have constructors
D. No, never
Solution: The abstract classes can always be used in multilevel inheritance. The only condition that may arise is that all the undefined functions must be defined in subclasses. There must not be any undefined function.
Q: How many abstract classes can be used in multilevel inheritance?
A. Only 1
B. Only 2
C. At least one less than number of levels
D. Can’t be used
Solution: At least one class must implement all the undefined functions. Hence there must be at least one class which is not abstract. That is at least one less than number of levels.

You Have Score    /10