iGET

C++ Programming - MCQ Practice Questions

C++ MCQs — OOP, STL, pointers, templates for coding rounds & IT exams.

100 questions | 100% Free

Q.21Medium

What is the output of the following code? class Base { public: virtual void display() { cout << "Base"; } }; class Derived : public Base { public: void display() { cout << "Derived"; } }; int main() { Base* ptr = new Derived(); ptr->display(); }

Q.22Medium

Which of the following statements about abstract classes in C++ is correct?

Q.23Medium

What will be the output of the following code? class A { public: A() { cout << "A "; } }; class B : public A { public: B() { cout << "B "; } }; int main() { B obj; }

Q.24Easy

In C++, what is the correct syntax for a pure virtual function?

Q.25Easy

Which access specifier allows a derived class to access members of the base class?

Q.26Medium

What is the main difference between method overloading and method overriding?

Q.27Hard

Consider the following code: class A { public: virtual ~A() {} }; class B : public A { public: ~B() {} }; int main() { A* ptr = new B(); delete ptr; } What is the significance of virtual destructor here?

Q.28Medium

What does encapsulation in C++ primarily achieve?

Q.29Hard

How is the Diamond Problem solved in C++ using virtual inheritance?

Q.30Medium

What is the purpose of the 'const' keyword when applied to member functions?

Q.31Hard

Which of the following is NOT a characteristic of a good object-oriented design?

Q.32Hard

Which of the following best describes the Liskov Substitution Principle (LSP)?

Q.33Medium

What happens when you try to call a non-virtual function through a pointer to a base class pointing to a derived object?

Q.34Easy

In C++, what is the correct way to implement an interface-like behavior?

Q.35Easy

Which of the following is a key principle of Object-Oriented Programming that bundles data and methods together?

Q.36Easy

In C++, what is the default access specifier for members of a class?

Q.37Medium

Which keyword is used to prevent a derived class from further overriding a virtual function in C++?

Q.38Medium

What is the output of the following code? class Base { public: void display() { cout << "Base"; } }; class Derived : public Base { public: void display() { cout << "Derived"; } }; Base obj = Derived(); obj.display();

Q.39Easy

Which of the following correctly describes a pure virtual function in C++?

Q.40Easy

In C++, an abstract class is a class that contains at least one _______.