Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

#include<iostream>using namespace std;class Base{public:virtual void show() = 0;};int main(void){Base b;Base *bp;return 0;}(A) There are compiler errors in lines “Base b;” and “Base bp;”(B) There is compiler error in line “Base b;”(C) There is compiler error in line “Base bp;”(D) No compiler Error

Answer»
2.

Which of the following is true about virtual functions in C++.(A) Virtual functions are functions that can be overridden in derived class with the same signature.(B) Virtual functions enable run-time polymorphism in a inheritance hierarchy.(C) If a function is ‘virtual’ in the base class, the most-derived class’s implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference.In non-virtual functions, the functions are called according to the type of reference or pointer.(D) All of the above

Answer»
3.

Output of following program#include<iostream>using namespace std;class Base{public:virtual void show() { cout<<" In Base \n"; }};class Derived: public Base{public:void show() { cout<<"In Derived \n"; }};int main(void){Base *bp, b;Derived d;bp = &d;bp->show();bp = &b;bp->show();return 0;}(A)In Base In Base (B)In Base In Derived(C)In DerivedIn Derived(D)In DerivedIn Base

Answer»
4.

Predict output of the following program#include<iostream>using namespace std;class Base{public:virtual void show() { cout<<" In Base \n"; }};class Derived: public Base{public:void show() { cout<<"In Derived \n"; }};int main(void){Base *bp = new Derived;bp->show();Base &br = *bp;br.show();return 0;}(A)In Base In Base (B)In Base In Derived(C)In DerivedIn Derived(D)In DerivedIn Base

Answer»
5.

Predict the output of following program.#include<iostream>using namespace std;class Base{public:virtual void show() = 0;};class Derived : public Base { };int main(void){Derived q;return 0;}(A) Compiler Error: there cannot be an empty derived class(B) Compiler Error: Derived is abstract(C) No compiler Error

Answer»
6.

Which of the following is true about pure virtual functions?1) Their implementation is not provided in a class where they are declared.2) If a class has a pure virtual function, then the class becomes abstract class and an instance of this class cannot be created.(A) Both 1 and 2(B) Only 1(C) Only 2(D) Neither 1 nor 2

Answer»