Test Series - oops

Test Number 39/78

Q: How many types of inheritance are possible in C++?
A. 2
B. 3
C. 4
D. 5
Solution: There are five types of inheritance that are possible in C++. Single level, Multilevel, multiple, hierarchical and hybrid. Here we count hybrid also because it sometimes can bring up a new form of inheritance, Like inheritance using multiple and hierarchical, which sometimes results in diamond problem.
Q: Which among the following is true?
A. Java supports all types of inheritance
B. Java supports multiple inheritance
C. Java doesn’t support multiple inheritance
D. Java doesn’t support inheritance
Solution: Java doesn’t support multiple inheritance. This is done to avoid the diamond problem that sometimes arises with inherited functions. Though, multiple inheritance can be implemented in java using interfaces.
Q: Which among the following best describes multiple inheritance?
A. Two classes being parent of any other classes
B. Three classes being parent of other classes
C. More than one class being parent of other child classes
D. More than one class being parent of single child
Solution: If a class inherits more than one class, it is known as multiple inheritance. This should not be referred with only two or three classes being inherited. But there must be one class which inherits more than one class to be called as multiple inheritance.
Q: How many types of inheritance can be used at a time in a single program?
A. Any two types
B. Any three types
C. Any 4 types
D. Any type, any number of times
Solution: Any type of inheritance can be used in any program. There is no rule to use only few types of inheritance. Only thing that matters is how the classes are inherited and used.
Q: Which type of inheritance results in the diamond problem?
A. Single level
B. Hybrid
C. Hierarchical
D. Multilevel
Solution: In diamond problem, hierarchical inheritance is used first, where two different classes inherit the same class and then in turn a 4th class inherits the two classes which had inherited the first class. Using more than one type of inheritance here, it is known as hybrid inheritance.
Q: If 6 classes uses single level inheritance with pair classes (3 pairs), which inheritance will this be called?
A. Single
B. Multiple
C. Hierarchical
D. Multilevel
Solution: Here all the pairs are using single inheritance. And no different pairs are inheriting same classes. Hence it can’t be called hybrid or multilevel inheritance. You can say the single inheritance is used 3 times in that program.
Q: Which among the following is false?
A. If one class inherits the inherited class in single level inheritance, it is multi-level inheritance
B. Hybrid inheritance always contains multiple inheritance
C. Hierarchical inheritance involves inheriting same class into more than one classes
D. Hybrid inheritance can involve any types of inheritance together
Solution: It is not necessary to have multiple inheritance in hybrid type. It can have any type together. This doesn’t have to be of specific type always.
Q: If class A has two nested classes B and C. Class D has one nested class E, and have inherited class A. If E inherits B and C, then ________________
A. It shows multiple inheritance
B. It shows hierarchical inheritance
C. It shows multiple inheritance
D. Multiple inheritance among nested classes, and single level for enclosing classes
Solution: This involves the same concept of inheritance, where the nested classes also follow the inheritance rules. The Enclosing classes are having single inheritance. Nested classes involves multiple.
Q: Which type of inheritance cannot involve private inheritance?
A. Single level
B. Multiple
C. Hybrid
D. All types can have private inheritance
Solution: This is a common type of inheritance where the protected and public members of parent class become private members in child class. There is no type which doesn’t support private inheritance.
Q: If multi-level inheritance is used, First class B inherits class A, then C inherits B and so on. Till how many classes can this go on?
A. Only till class C
B. Only till class J
C. Only till class Z
D. There is no limit
Solution: In this case, there is no limit. All the classes going on like this will inherit the members of base class, and hence the upper level inheritance won’t affect the number of classes that can go on inheriting in this pattern.

You Have Score    /10