MCQ Bank
Which of the following creates the strongest relationship between two objects?
- A) Association
- B) Inheritance
- C) Aggregation
- D) Composition
In C++, if new operator is used, when is the constructor called?
- A) Before the allocation of memory
- B) Constructor is called to allocate memory
- C) Depends on code
- D) After the allocation of memory
An operator in C++ can be overloaded using ________ keyword.
- A) Load
- B) Switch
- C) Operator
- D) Overload
Overloading binary operator as a member function of a class requires ____________ argument/s.
- A) 3
- B) 0
- C) 2
- D) 1
“Static data member is declared ___ the class, but they are defined ___ the class.” Choose the correct sequence of data member declaration and definition.
- A) Inside, Outside
- B) Outside, Inside
- C) Inside, Inside
- D) Outside, Outside
#include<iostream> #include <stdio.h> using namespace std; void test() { static int count = 0; count++; cout<<" "<<count; } int main() { test(); test(); test(); return 0; } What will be the correct output of above code?
- A) 1 2 3
- B) 1 1 2
- C) 1 1 1
- D) 3 3 3
Which of the following is true about the friend functions?
- A) Friend functions can be placed anywhere in the class
- B) Prototypes of friend functions appear in the class definition.
- C) Access specifiers has no impact on friend functions or classes
- D) All of the given options
Which of the following is a weak relationship?
- A) Aggregation
- B) Composition
- C) Association
- D) Inheritance
When an object of a class is the data member of another class, it is called as _________.
- A) aggregation
- B) composition
- C) inheritance
- D) Association
Why do we need relationships between classes?
- A) To increase code re-usability
- B) To enhance the communication between classes
- C) All of the given option
- D) To use the functionality of one class into derived classes
Static data members are shared by _____ of the class.
- A) Public data members
- B) Protected data members
- C) All types of data members
- D) Private data members
Suppose c1, c2, and c3 are the objects of the Complex class and we overloaded the + operator. c3 = c1 + c2; In this statement, ___________ object will be passed as argument when + operator is called.
- A) c3
- B) c1
- C) c1 and c2
- D) c2
Which of the following keyword should be used to declare a static variable?
- A) const
- B) stat
- C) global
- D) static
Which statement is not true for static member functions?
- A) They are used to access static data members.
- B) They cannot access any non-static members.
- C) Access mechanism for static member functions is same as that of static data members.
- D) They are capable to access static as well as non-static member functions.
In C++, when a binary overloaded operator "+" is called, ______________ is passed as an argument.
- A) Right hand operand
- B) Left hand operand
- C) Pointer
- D) Dot operator
Which of the following option correctly declares a static variable ‘x’ ?
- A) int static x;
- B) static x int;
- C) static int x;
- D) int x static;
What will be the output of the following program? #include<iostream> using namespace std; class House{ private: int rooms; public: House() { cout<<"Entering the house"<<endl;} House(int R) { rooms = R;} ~House() { cout<<"Leaving the house"<<endl;} }; class Kitchen : public House { double size; public: Kitchen() : House() { cout<<"Entering the kitchen";} }; int main() { Kitchen Obj; return 0; }
- A) Entering the kitchen Entering the house Leaving the house
- B) Entering the house Leaving the house Entering the kitchen
- C) Entering the house Entering the kitchen Leaving the house
- D) Leaving the house Entering the house Entering the kitchen
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) 40
- C) 10
- D) 30
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) None of the given options
- B) Both
- C) Overloaded
- D) Overridden
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;