Test Series - oops

Test Number 43/78

Q: How many base classes can a derived class have which is implementing multiple inheritance?
A. Only 2
B. At least 2
C. At most 2
D. As many as required
Solution: The classes can derive from as many classes as required since the multiple inheritance feature is made to combine or group together the functions that are from different classes. This make the derived class stronger in terms of its flexibility.
Q: How to overcome diamond problem?
A. Using alias name
B. Using seperate derived class
C. Using virtual keyword with same name function
D. Can’t be done
Solution: To overcome the ambiguity and conflict we can use keyword virtual. This will help us to differentiate the functions with same name that came to last derived class in diamond problem.
Q: When multiple inheritance is used, which class object should be used in order to access all the available members of parent and derived class?
A. Derived class object
B. Parent class objects
C. Use Abstract derived class
D. Derive a class from derived class
Solution: The derived class object can access all of its own members. It can also access the available members of the parent classes, because the members are derived into the derived class.
Q: If all the members of all the base classes are private then _____________
A. There won’t be any use of multiple inheritance
B. It will make those members public
C. Derived class can still access them in multiple inheritance
D. Compile time error
Solution: The derived class will not be able to access any members of the base classes. Since private member’s are not inheritable. It leads to no use of multiple inheritance.
Q: Is it compulsory to have constructor for all the classes involved in multiple inheritance?
A. Yes, always
B. Yes, only if no abstract class is involved
C. No, only classes being used should have a constructor
D. No, they must not contain constructors
Solution: The constructors must be defined in every class. If class is abstract, it won’t have any constructor but other classes must have constructor. Either implicit or explicit.
Q: If a class contains 2 nested class and is being inherited by another class, will there be any multiple inheritance?
A. No, only single level inheritance is used
B. No, only multilevel inheritance is used
C. Yes, because 3 classes are involved
D. Yes, because more than 1 classes are being derived
Solution: When a class having nested classes is being derived into another class. It indirectly means a simple class is being inherited to another class. This is single level inheritance.
Q: Which members can’t be accessed in derived class in multiple inheritance?
A. Private members of base
B. Public members of base
C. Protected members of base
D. All the members of base
Solution: The private member’s are available for only the class containing those members. Derived classes will have access to protected and public members only.
Q: Can the derived class be made abstract if multiple inheritance is used?
A. No, because other classes must be abstract too
B. Yes, if all the functions are implemented
C. Yes, if all the methods are predefined
D. No, since constructors won’t be there
Solution: The derived class must not be abstract. This is because the abstract classes doesn’t have constructor and hence we won’t be having the capability to have instances. This will restrict the use of multiple inheritance.
Q: Which among the following is best to define hierarchical inheritance?
A. More than one classes being derived from one class
B. More than 2 classes being derived from single base class
C. At most 2 classes being derived from single base class
D. At most 1 class derived from another class
Solution: When two or more classes get derived from a single base class, it is known as hierarchical inheritance. This gives us freedom to use same code with different scopes and flexibility into different classes.
Q: Do members of base class gets divided among all of its child classes?
A. Yes, equally
B. Yes, depending on type of inheritance
C. No, it’s doesn’t get divided
D. No, it may or may not get divided
Solution: The class members doesn’t get divided among the child classes. All the members get derived to each of the subclasses as whole. The only restriction is from the access specifiers used.

You Have Score    /10