6.
Can we pass parameters to base class constructor though derived class or derived class constructor?
A. Yes
B. No
C. May Be
D. Can’t Say
Ans : A
Explanation: Yes, we pass parameters to base class constructor though derived class or derived class constructor.
7.
What are the things are inherited from the base class?
A. Constructor and its destructor
B. Operator=() members
C. Friends
D. All of the above
Ans : D
Explanation: These things can provide necessary information for the base class to make a logical decision.
8.
Types of inheritance in C++ are
A. Multilevel
B. Multiple
C. Hierarchical
D. All the above
Answer: D
Explanation: All are types of inheritance relationship in C++ oops.
Multilevel Inheritance: When a class is derived from a class which is also derived from another class.
Multiple Inheritance: A class inherits multiple class. or say, A class has more than one base class.
Hierarchical Inheritance: When multiple classes derived from a same base class.
9.
What will be the output of the following program?
#include<iostream>
using namespace std;
class find {
public:
void print() { cout <<" In find"; }
};
class course : public find {
public:
void print() { cout <<" In course"; }
};
class tech: public course { };
int main()
{
tech t;
t.print();
return 0;
}
A. In find
B. In course
C. Compiler Error: Ambiguous call to print()
D. None of the above
Ans : B
Explanation: The print findction is not present in class tech. So it is looked up in the inheritance hierarchy. print() is present in both classes find and course, which of them should be called? The idea is, if there is multilevel inheritance, then findction is linearly searched up in the inheritance hierarchy until a matching findction is found.
10.
Which symbol is used to create multiple inheritance?
A. Dot
B. Comma
C. Dollar
D. None of the above
Ans : B
Explanation: For using multiple inheritance, simply specify each base class (just like in single inheritance), separated by a comma.