Skip to main content

Inheritance In C Plus Plus — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Inheritance In C Plus Plus — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
34
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
41 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
34

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/34 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Mammal { public: Mammal(){ cout<<"I'm a Mammal\n"; } ~Mammal(){} }; class Human: public Mammal { public: Human(){ cout<<"I'm a Human\n"; } ~Human(){} }; class Male: public Human { public: Male(){ cout<<"I'm a Male\n"; } ~Male(){} }; class Female: public Human { public: Female(){ cout<<"I'm a Female\n"; } ~Female(){} }; int main(int argc, char const *argv[]) { Male M; return 0; }

Question 2 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: virtual void func(){ cout<<"Hello this is class A\n"; } }; class B: public A { int a = 15; public: void func(){ cout<<"Hello this is class B\n"; } }; int main(int argc, char const *argv[]) { A *a; a->func(); return 0; }

Question 3 of 34
★ FPSC ★ PPSC

Which statement is incorrect about virtual function.

Question 4 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: public A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }

Question 5 of 34
★ FPSC ★ PPSC

Which is the correct syntax of declaring a virtual function?

Question 6 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } static void show(){ a++; cout<<a; } }; class B: public A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }

Question 7 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { public: virtual A(){ cout<<"A's Constructor\n"; } }; class B: public A { public: A(){ cout<<"Present inside the class B\n"; } }; int main(int argc, char const *argv[]) { A a; return 0; }

Question 8 of 34
★ FPSC ★ PPSC

What happens if the following C++ program is compiled? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: private A { public: void show(){ show(); } }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }

Question 9 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class Base { public: virtual void print() const = 0; }; class DerivedOne : public Base { public: void print() const { cout << "DerivedOne\n"; } }; class DerivedTwo : public Base { public: void print() const { cout << "DerivedTwo\n"; } }; class Multiple : public DerivedOne, public DerivedTwo { public: void print() const { DerivedTwo :: print(); } }; int main() { int i; Multiple both; DerivedOne one; DerivedTwo two; Base *array[ 3 ]; array[ 0 ] = &both; array[ 1 ] = &one; array[ 2 ] = &two; array[ i ] -> print(); return 0; }

Question 10 of 34
★ FPSC ★ PPSC

Which design patterns benefit from the multiple inheritances?

Question 11 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { public: virtual static void show(){ cout<<"class A\n"; } }; class B: public A { public: static void show(){ cout<<"class B\n"; } }; int main(int argc, char const *argv[]) { A *a = new A(); B b; a = &b; a->show(); return 0; }

Question 12 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: A(){ cout<<"Constructor of class A\n"; } }; class B: public A { int a = 15; public: B(){ cout<<"Constructor of class B\n"; } }; int main(int argc, char const *argv[]) { B b; return 0; }

Question 13 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class student { public: int rno , m1 , m2 ; void get() { rno = 15, m1 = 10, m2 = 10; } }; class sports { public: int sm; void getsm() { sm = 10; } }; class statement:public student,public sports { int tot,avg; public: void display() { tot = (m1 + m2 + sm); avg = tot / 3; cout << tot; cout << avg; } }; int main() { statement obj; obj.get(); obj.getsm(); obj.display(); }

Question 14 of 34
★ FPSC ★ PPSC

What is a pure virtual function?

Question 15 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Mammal { public: virtual void Define(){ cout<<"I'm a Mammal\n"; } }; class Human: public Mammal { public: void Define(){ cout<<"I'm a Human\n"; } }; class Male: public Human { public: void Define(){ cout<<"I'm a Male\n"; } }; class Female: public Human { public: void Define(){ cout<<"I'm a Female\n"; } }; int main(int argc, char const *argv[]) { Mammal *M = new Mammal(); Male m; Female f; *M = m; M->Define(); M = &m; M->Define(); return 0; }

Question 16 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; struct a { int count; }; struct b { int* value; }; struct c : public a, public b { }; int main() { c* p = new c; p->value = 0; cout << "Inherited"; return 0; }

Question 17 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class Base1 { protected: int SampleDataOne; public: Base1() { SampleDataOne = 100; } ~Base1() { } int SampleFunctOne() { return SampleDataOne; } }; class Base2 { protected: int SampleDataTwo; public: Base2() { SampleDataTwo = 200; } ~Base2() { } int SampleFunctTwo() { return SampleDataTwo; } }; class Derived1 : public Base1, public Base2 { int MyData; public: Derived1() { MyData = 300; } ~Derived1() { } int MyFunct() { return (MyData + SampleDataOne + SampleDataTwo); } }; int main() { Base1 SampleObjOne; Base2 SampleObjTwo; Derived1 SampleObjThree; cout << SampleObjThree.Base1 :: SampleFunctOne() << endl; cout << SampleObjThree.Base2 :: SampleFunctTwo() << endl; return 0; }

Question 18 of 34
★ FPSC ★ PPSC

Which of the following advantages we lose by using multiple inheritances?

Question 19 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: private A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }

Question 20 of 34
★ FPSC ★ PPSC

What is a virtual function in C++?

Question 21 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: int a; void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; class B: public A { int a = 15; public: void print(){ cout<<a; } }; int main(int argc, char const *argv[]) { B b; b.change(10); b.print(); b.value_of_a(); return 0; }

Question 22 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Mammal { public: virtual void Define(){ cout<<"I'm a Mammal\n"; } }; class Human: public Mammal { private: void Define(){ cout<<"I'm a Human\n"; } }; int main(int argc, char const *argv[]) { Mammal *M = new Mammal(); Human H; M = &H; M->Define(); return 0; }

Question 23 of 34
★ FPSC ★ PPSC

Which concept of OOPs is shown by Virtual Functions?

Question 24 of 34
★ FPSC ★ PPSC

Virtual functions in C++ tells the compiler to perform . . . . . . . . on such functions.

Question 25 of 34
★ FPSC ★ PPSC

The concept of deciding which function to invoke during runtime is called . . . . . . . .

Question 26 of 34
★ FPSC ★ PPSC

What is the order of Destructors call when the object of derived class B is declared, provided class B is derived from class A?

Question 27 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a, b; float d; public: void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; class B: private A { }; int main(int argc, char const *argv[]) { B b; cout<<sizeof(B); return 0; }

Question 28 of 34
★ FPSC ★ PPSC

What are the things are inherited from the base class?

Question 29 of 34
★ FPSC ★ PPSC

What is the order of Constructors call when the object of derived class B is declared, provided class B is derived from class A?

Question 30 of 34
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class polygon { protected: int width, height; public: void set_values (int a, int b) { width = a; height = b;} }; class output1 { public: void output (int i); }; void output1::output (int i) { cout << i << endl; } class rectangle: public polygon, public output1 { public: int area () { return (width * height); } }; class triangle: public polygon, public output1 { public: int area () { return (width * height / 2); } }; int main () { rectangle rect; triangle trgl; rect.set_values (4, 5); trgl.set_values (4, 5); rect.output (rect.area()); trgl.output (trgl.area()); return 0; }

Question 31 of 34
★ FPSC ★ PPSC

Which symbol is used to create multiple inheritances?

Question 32 of 34
★ FPSC ★ PPSC

How many specifiers are used to derive a class?

Question 33 of 34
★ FPSC ★ PPSC

If a class is derived privately from a base class then . . . . . . . .

Question 34 of 34
★ FPSC ★ PPSC

What is meant by multiple inheritance?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →