MCQ Bank
An operator in C++ can be overloaded using ________ keyword.
- A) Load
- B) Overload
- C) Switch
- D) Operator
In C++, when a binary overloaded operator "+" is called, ______________ is passed as an argument.
- A) Pointer
- B) Left hand operand
- C) Dot operator
- D) Right hand operand
Which statement is not true for static member functions?
- A) They are used to access static data members.
- B) Access mechanism for static member functions is same as that of static data members.
- C) They cannot access any non-static members.
- D) They are capable to access static as well as non-static member functions.
Which of the following is true about the friend functions?
- A) Friend functions can be placed anywhere in the class
- B) All of the given options
- C) Access specifiers has no impact on friend functions or classes
- D) Prototypes of friend functions appear in the class definition.
Which of the following keyword should be used to declare a static variable?
- A) stat
- B) static
- C) const
- D) global
Which of the following option correctly declares a static variable ‘x’ ?
- A) int x static;
- B) static x int;
- C) static int x;
- D) int static x;
What will be the output of the given code extract? int y = 2; cout << ++y << " " << y;
- A) 3 3
- B) 2 2
- C) 2 3
- D) 3 2
What will be the output of following C++ code? int a=5; cout<<a++;
- A) a
- B) 5
- C) 6
- D) 0
cout is an object of ____ class.
- A) ostream
- B) instream
- C) fstream
- D) istream
Which of the following is unary operator in C++?
- A) ++
- B) +
- C) -
- D) *
Which of the following is correct symbol of stream extraction operator?
- A) <
- B) <<
- C) >
- D) >>
"cin" is an object of ____ class.
- A) fstream
- B) instream
- C) istream
- D) ostream
#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 1 1
- B) 3 3 3
- C) 1 1 2
- D) 1 2 3
Which statement is true about life of a static data member?
- A) Static data members are destroyed when single object of a class is destroyed.
- B) Static members are destroyed dynamically.
- C) Static data member exists only within the scope of the class constructor.
- D) They remains in memory even if all objects are destroyed.
The relationship between container and contained objects is called ___________.
- A) Composition
- B) Inheritance
- C) Association
- D) Aggregation
“Static data member is declared ___ the class, but they are defined ___ the class.” Choose the correct sequence of data member declaration and definition.
- A) Outside, Outside
- B) Outside, Inside
- C) Inside, Inside
- D) Inside, Outside
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 Entering the kitchen Leaving the house
- C) Leaving the house Entering the house Entering the kitchen
- D) Entering the house Leaving the house Entering the kitchen
In the case of protected inheritance, public members of the base class will be _____________ in the derived class.
- A) Private
- B) Public
- C) Hidden
- D) Protected
Which of the following members of base class can be accessed in the derived class?
- A) Both Public and Private
- B) All (Public, Protected, and Private)
- C) Both Protected and Private
- D) Both Protected and Public
If the programmer does not specify the type of inheritance then the default type of inheritance is ____________.
- A) None of the given
- B) Protected
- C) Private
- D) Public