MCQ Bank
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) Both
- D) Overridden
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) Shape::draw()
- B) Line::draw()
- C) Circle::draw()
- D) Error
virtual void print(); is an example of_________________.
- A) pure virtual function
- B) virtual function
- C) template function
- D) simple function
In dynamic binding, the function call is resolved:
- A) At linking time
- B) During compilation
- C) Before compilation
- D) During execution
A class with pure virtual function is called ________ class.
- A) normal
- B) abstract
- C) concrete
- D) solid
Static binding means:
- A) Function selected randomly
- B) Function selected randomly
- C) Function selected at run time
- D) Function selected at compile time
Which binding is also called late binding?
- A) Dynamic binding
- B) Early binding
- C) Static binding
- D) Compile-time binding
Virtual functions can be used in ________ ways.
- A) 8
- B) 0
- C) 6
- D) 2
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) void sum()=0;
- D) virtual void sum()=0;
Which keyword is used to achieve polymorphism?
- A) virtual
- B) poly
- C) polymorphism
- D) pure virtual
Which of the following is the correct syntax for creating a function Test(T) friend of a template class?
- A) void Test(T);
- B) friend void Test(T);
- C) void friend Test(T);
- D) void Test(T) friend;
Which of the following instantiates a template with explicit type?
- A) typename max(a,b)
- B) max<T>(a, b)
- C) max(a, b)
- D) template max(a,b)
Which one of the following is an example of complete specialization?
- A) template <class T> class Vector<T *> { }
- B) template <typename T> class Vector { }
- C) template <typename T> class Vector<T*> { }
- D) template<> class Vector <char*> { }
Which of the following is the correct syntax for creating a template class X friend of a template class Y?
- A) friend X<T>;
- B) X<T> friend;
- C) X<T>;
- D) friend X;
Which keyword is used to define a template in C++?
- A) typename
- B) class
- C) template
- D) function
What keyword is used to define a generic function template?
- A) template
- B) typename
- C) generic
- D) class
If a function template has parameters `T` and `U`, calling `func(1, 2.5)` results in:
- A) Both deduced as int
- B) T=int, U=double
- C) Both deduced as double
- D) Compilation error
How can you define a class template in C++?
- A) template<name T> class MyClass { ... };
- B) template<type T> class MyClass { ... };
- C) template<class T> MyClass { ... };
- D) template<typename T> class MyClass { ... };
Function templates are preferred over overloading when
- A) They have different names
- B) They return different types
- C) They have different numbers of arguments
- D) Functions differ only by parameter types
Which of the following is an example of partial specialization?
- A) template<int>
- B) template<int , float , char>
- C) template<class T, class U>
- D) template<class T, float>