C++ Programming - MCQ Practice Questions
C++ MCQs — OOP, STL, pointers, templates for coding rounds & IT exams.
100 questions | 100% Free
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(); }
Which of the following statements about abstract classes in C++ is correct?
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; }
In C++, what is the correct syntax for a pure virtual function?
Which access specifier allows a derived class to access members of the base class?
What is the main difference between method overloading and method overriding?
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?
What does encapsulation in C++ primarily achieve?
How is the Diamond Problem solved in C++ using virtual inheritance?
What is the purpose of the 'const' keyword when applied to member functions?
Which of the following is NOT a characteristic of a good object-oriented design?
Which of the following best describes the Liskov Substitution Principle (LSP)?
What happens when you try to call a non-virtual function through a pointer to a base class pointing to a derived object?
In C++, what is the correct way to implement an interface-like behavior?
Which of the following is a key principle of Object-Oriented Programming that bundles data and methods together?
In C++, what is the default access specifier for members of a class?
Which keyword is used to prevent a derived class from further overriding a virtual function in C++?
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();
Which of the following correctly describes a pure virtual function in C++?
In C++, an abstract class is a class that contains at least one _______.