Home Subjects C++ Programming OOP Concepts

C++ Programming
OOP Concepts

Object oriented C++ for GATE and placement

49 Q 1 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–49 of 49
Topics in C++ Programming
All OOP Concepts 100
Q.41 Medium OOP Concepts
What is the main advantage of using interfaces/abstract classes in C++?
A To increase execution speed
B To define a contract that derived classes must follow
C To reduce memory usage
D To enable multiple return values
Correct Answer:  B. To define a contract that derived classes must follow
EXPLANATION

Abstract classes define a contract (interface) that derived classes must implement. This ensures consistency and enables polymorphic behavior across different derived classes.

Test
Q.42 Medium OOP Concepts
Which of the following is a characteristic of a pure virtual function?
A It must have a body
B It must be overridden in derived classes
C It can be called directly from main()
D It is always private
Correct Answer:  B. It must be overridden in derived classes
EXPLANATION

A pure virtual function (defined with = 0) must be overridden in derived classes. The base class containing it becomes abstract and cannot be instantiated.

Test
Q.43 Medium OOP Concepts
Which of the following demonstrates proper encapsulation?
A class Account { public: int balance; };
B class Account { private: int balance; public: void setBalance(int b) {} int getBalance() {} };
C class Account { protected: int balance; };
D class Account { int balance; }; // No accessor methods
Correct Answer:  B. class Account { private: int balance; public: void setBalance(int b) {} int getBalance() {} };
EXPLANATION

Proper encapsulation hides data members (private) and provides controlled access through public getter and setter methods.

Test
Q.44 Medium OOP Concepts
What is a copy constructor in C++?
A A constructor that creates a duplicate of an existing object
B A constructor that copies data from a file
C A constructor that initializes all members to zero
D A constructor with no parameters
Correct Answer:  A. A constructor that creates a duplicate of an existing object
EXPLANATION

A copy constructor takes a reference to another object of the same class and creates a copy of it. Syntax: ClassName(const ClassName &obj);

Test
Q.45 Medium OOP Concepts
Which type of inheritance can lead to the Diamond Problem in C++?
A Single inheritance
B Multiple inheritance
C Multilevel inheritance
D Hybrid inheritance
Correct Answer:  B. Multiple inheritance
EXPLANATION

Multiple inheritance can lead to the Diamond Problem where a class inherits from two classes that share a common base. This is solved using virtual inheritance.

Test
Q.46 Medium OOP Concepts
Which of the following is true about abstract classes in C++?
A C++ has a dedicated 'abstract' keyword
B Abstract classes are created using pure virtual functions
C You can instantiate an abstract class
D Abstract classes cannot have constructors
Correct Answer:  B. Abstract classes are created using pure virtual functions
EXPLANATION

C++ doesn't have a dedicated 'abstract' keyword. Abstract classes are created by defining at least one pure virtual function (virtual func() = 0;). You cannot instantiate abstract classes.

Test
Q.47 Medium OOP Concepts
What is the difference between method overloading and method overriding?
A Overloading is in same class, overriding is in derived class
B Overloading changes return type, overriding changes parameters
C They are the same thing
D Overloading is compile-time, overriding is runtime
Correct Answer:  A. Overloading is in same class, overriding is in derived class
EXPLANATION

Method overloading occurs in the same class with different parameter lists (compile-time polymorphism). Method overriding occurs in derived classes with the same signature (runtime polymorphism).

Test
Q.48 Medium OOP Concepts
What will be the output of the following code?
class Base {
public:
virtual void display() { cout
A Base
B Derived
C Compilation Error
D No Output
Correct Answer:  B. Derived
EXPLANATION

Due to virtual function and dynamic polymorphism, the Derived class's display() method is called because the actual object is of type Derived, even though the pointer is of type Base.

Test
Q.49 Medium OOP Concepts
Which of the following correctly demonstrates constructor overloading?
A class A { A() {} A(int x) {} };
B class A { void A() {} void A(int x) {} };
C class A { A() {} A() {} };
D class A { A(int) {} A(int) {} };
Correct Answer:  A. class A { A() {} A(int x) {} };
EXPLANATION

Constructor overloading allows multiple constructors with different parameter lists. Option A is correct as it has constructors with no parameters and with an int parameter.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips