MCQ Bank
In the case of public inheritance, private members of the base class will be _____________ in the derived class.
- A) Hidden
- B) Protected
- C) Private
- D) Public
Consider the code below, class class1{ public: void func1(); }; class class2 : public class1 { }; Function func()1 of class1 is ______ in class2.
- A) Public
- B) Hidden
- C) Private
- D) Protected
In the case of private inheritance, public members of the base class will be _____________ in the derived class.
- A) Protected
- B) Hidden
- C) Public
- D) Private
What will be the output of the following program? #include<iostream> using namespace std; class FirstNumber { private: int x; public: int y; FirstNumber () { x = 0; y = 10; } }; class SecondNumber: public FirstNumber { int z; public: int w; SecondNumber () : FirstNumber () { z = 20; w = y + z; cout<<w;} }; int main() { SecondNumber Obj; return 0; }
- A) 20
- B) 30
- C) 10
- D) 40
Which inheritance type is used to implement IS-A relationship?
- A) Private
- B) Multiple
- C) Public
- D) Protected
Which one of the following is an example of complete specialization?
- A) template<> class Vector <char*> { }
- B) template <typename T> class Vector { }
- C) template <class T> class Vector<T *> { }
- D) template <typename T> class Vector<T*> { }
Which keyword is used to define a template in C++?
- A) template
- B) class
- C) typename
- D) function
Which of the following is the correct syntax for creating a template class X friend of a template class Y?
- A) X<T>;
- B) friend X<T>;
- C) X<T> friend;
- D) friend X;
What is the name of Base class in the line below? class Truck : public Vehicle
- A) Truck
- B) Public
- C) None of the given options
- D) Vehicle
To accept two type parameters, __________ is written.
- A) template<class T, U>
- B) template<class T U>
- C) template<typename T U>
- D) template<typename T, typename U>
Which of the following is true about friend functions in template classes?
- A) They can only access public members of the class.
- B) They are inherited by derived classes.
- C) They must be defined inside the class.
- D) They can access private and protected members of the class.
Which of the following instantiates a template with explicit type?
- A) max<T>(a, b)
- B) typename max(a,b)
- C) max(a, b)
- D) template max(a,b)
In case of public inheritance between Base class A and Derived class B, which of the folllowing data members of Base class will be hidden in Derived class?
- A) private
- B) public
- C) both public and private
- D) protected
class A { public: int Test(int x) {return x*x;} int Test(int x,int y) {return x*y;} }; class B : public A { public: int Test(int x) { return x*x*x;} }; In the above class, the method Test is_______.
- A) Overloaded
- B) None of the given options
- C) Overridden
- D) Both
For the given class definition, which one is correct? #include<iostream> using namespace std; class A{ int x,y; public: int Add(int a,int b){return a+b;} int Add(int c){return c;} };
- A) Function Add has an error
- B) Function Add is overridden
- C) None of the given options
- D) Function Add is overloaded
There are ________ types of inheritance in C++.
- A) 2
- B) 4
- C) 3
- D) 1
Which of the following is not the correct type of inheritance in C++?
- A) public
- B) secret
- C) private
- D) protected
Shape is a base class and Line is a derived class. The draw() function is not declared as virtual in the base class. Which function will be called? Shape* s = new Line(); s->draw();
- A) Error
- B) Shape::draw()
- C) Circle::draw()
- D) Line::draw()
Which binding is also called late binding?
- A) Compile-time binding
- B) Dynamic binding
- C) Static binding
- D) Early binding
Suppose you have a function: void sum(); Choose correct syntax from the given options which will make this function pure virtual function.
- A) void sum() virtual=0;
- B) sum()=0;
- C) virtual void sum()=0;
- D) void sum()=0;