MCQOPTIONS
Saved Bookmarks
This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Technical MCQs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
C++ Inheritance relationship is? |
| A. | Association |
| B. | Is-A |
| C. | Has-A |
| D. | None of the above |
| E. | |
| Answer» C. Has-A | |
| 2. |
#include <iostream>using namespace std; class Base{public: int lfc() { cout << "Base::lfc() called"; } int lfc(int i) { cout << "Base::lfc(int i) called"; }}; class Derived: public Base{public: int lfc() { cout << "Derived::lfc() called"; }}; int main(){ Derived d; d.lfc(5); return 0;}19.___________ inheritance may lead to duplication of inherited members from a "grandparent" base class. |
| A. | Multipath |
| B. | Multiple |
| C. | Multilevel |
| D. | Hierarchical |
| Answer» B. Multiple | |
| 3. |
#include <iostream>using namespace std;class Base {};class Derived: public Base {}; int main(){ Base *p = new Derived; Derived *q = new Base;}18.What will be the output of the following program? |
| A. | Base::lfc(int i) called |
| B. | Derived::lfc() called |
| C. | Base::lfc() called |
| D. | Compiler Error |
| Answer» E. | |
| 4. |
Note:Includes all required header filesusing namespace std; class base { int arr[15];}; class b1: public base { }; class b2: public base { }; class derived: public b1, public b2 {}; int main(void){ cout << sizeof(derived); return 0;}17.What will be the output of this program? |
| A. | error: invalid conversion from "Derived*" to "Base*" |
| B. | No Compiler Error |
| C. | error: invalid conversion from "Base*" to "Derived*" |
| D. | Runtime Error |
| Answer» D. Runtime Error | |
| 5. |
Note:Includes all required header filesusing namespace std; class Base1 { public: ~Base1() { cout << " Base1" << endl; }}; class Base2 { public: ~Base2() { cout << " Base2" << endl; }}; class Derived: public Base1, public Base2 { public: ~Derived() { cout << " Derived" << endl; }}; int main(){ Derived d; return 0;} 16.Assume that an integer takes 2 bytes and there is no alignment in following classes, predict the output. |
| A. | 30 |
| B. | 60 |
| C. | 0 |
| D. | 120 |
| Answer» E. | |
| 6. |
Note:Includes all required header filesusing namespace std; class Base1 { public: Base1() { cout << " Base1" << endl; }}; class Base2 { public: Base2() { cout << "Base2" << endl; }}; class Derived: public Base1, public Base2 { public: Derived() { cout << "Derived" << endl; }}; int main(){ Derived d; return 0;} 15.Which of the following is true about the following program |
| A. | Base1 Base2 Derived |
| B. | Derived Base2 Base1 |
| C. | Derived |
| D. | Compiler Dependent |
| Answer» C. Derived | |
| 7. |
Note:Includes all required header files using namespace std;struct a { int p; };struct b { int* x; };struct c : public a, public b { };int main() { c* p = new c; p->x = 0; cout << "Inherited"; return 0; } 14.What is the output of this program? |
| A. | Compiler Dependent |
| B. | Base1 Base2 Derived |
| C. | Base2 Base1 Derived |
| D. | Compiler Error |
| Answer» C. Base2 Base1 Derived | |
| 8. |
Note:Includes all required header files using namespace std; int main() { string s = "a long string"; s.insert(s.size() / 2, " * "); cout << s << endl; return 0; }13.What is the output of this program? |
| A. | Inherited |
| B. | Error |
| C. | Runtime error |
| D. | None of the mentioned |
| Answer» B. Error | |
| 9. |
Note:Includes all required header files using namespace std; class Base { public: Base(){} ~Base(){} protected: private: }; class Derived:public Base { public: Derived(){} Derived(){} private: protected: }; int main() { cout << "Executed" << endl; } 12.What is the output of this program? |
| A. | long* string |
| B. | a long st*ring |
| C. | Depends on compiler |
| D. | None of the mentione |
| Answer» D. None of the mentione | |