MCQ Bank
cout is an object of ____ class.
- A) ostream
- B) instream
- C) istream
- D) fstream
Which of the following is unary operator in C++?
- A) *
- B) +
- C) -
- D) ++
What will be the output of following C++ code? int a=5; cout<<a++;
- A) 6
- B) a
- C) 0
- D) 5
"cin" is an object of ____ class.
- A) instream
- B) ostream
- C) istream
- D) fstream
What will be the output of the given code extract? int y = 2; cout << ++y << " " << y;
- A) 3 3
- B) 2 3
- C) 2 2
- D) 3 2
Which of the following is correct symbol of stream extraction operator?
- A) >
- B) <
- C) <<
- D) >>
In the case of public inheritance, private members of the base class will be _____________ in the derived class.
- A) Private
- B) Protected
- C) Public
- D) Hidden
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) 30
- B) 10
- C) 40
- D) 20
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) Leaving the house Entering the house Entering the kitchen
- B) Entering the house Leaving the house Entering the kitchen
- C) Entering the kitchen Entering the house Leaving the house
- D) Entering the house Entering the kitchen Leaving the house
If the programmer does not specify the type of inheritance then the default type of inheritance is ____________.
- A) Private
- B) None of the given
- C) Protected
- D) Public
In the case of private inheritance, public members of the base class will be _____________ in the derived class.
- A) Private
- B) Hidden
- C) Protected
- D) Public
What is the name of Base class in the line below? class Truck : public Vehicle
- A) Vehicle
- B) None of the given options
- C) Truck
- D) Public
Consider the code below, class class1{ public: void func1(); }; class class2 : public class1 { }; Function func()1 of class1 is ______ in class2.
- A) Hidden
- B) Protected
- C) Private
- D) Public
Which inheritance type is used to implement IS-A relationship?
- A) Private
- B) Multiple
- C) Public
- D) Protected
Which of the following members of base class can be accessed in the derived class?
- A) Both Protected and Private
- B) Both Protected and Public
- C) All (Public, Protected, and Private)
- D) Both Public and Private
In the case of protected inheritance, public members of the base class will be _____________ in the derived class.
- A) Hidden
- B) Protected
- C) Public
- D) Private
There are ________ types of inheritance in C++.
- A) 1
- B) 4
- C) 2
- D) 3
Which of the following is not the correct type of inheritance in C++?
- A) protected
- B) secret
- C) public
- D) private
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) Function Add is overloaded
- D) None of the given options
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) protected
- B) public
- C) private
- D) both public and private