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 1–10 of 49
Topics in C++ Programming
All OOP Concepts 100
Q.1 Medium OOP Concepts
In C++, when a derived class overrides a virtual function from a base class, which access specifier must be used to ensure proper polymorphic behavior?
A The derived class function must use the same access specifier as the base class
B The derived class function can use any access specifier regardless of base class
C The derived class function must always be public
D The derived class function must be private for security
Correct Answer:  B. The derived class function can use any access specifier regardless of base class
EXPLANATION

In C++, a derived class can override a virtual function with a different access specifier than the base class. The access specifier controls who can call the function, but it doesn't affect the polymorphic behavior. However, it's a best practice to maintain the same access level.

Test
Q.2 Medium OOP Concepts
Which of the following best describes the concept of method overloading?
A Multiple functions with the same name and same parameters
B Multiple functions with the same name but different parameters or return types
C A derived class defining a function with the same name as the base class
D Using virtual functions to achieve runtime polymorphism
Correct Answer:  B. Multiple functions with the same name but different parameters or return types
EXPLANATION

Method overloading allows multiple functions with the same name but different parameter lists (number, type, or order). Return type alone is insufficient for overloading.

Test
Q.3 Medium OOP Concepts
What is the primary use of the 'const' keyword when applied to member functions?
A To prevent the function from modifying object data members
B To prevent the function from being called
C To make the function static
D To optimize function execution speed
Correct Answer:  A. To prevent the function from modifying object data members
EXPLANATION

A const member function cannot modify any non-static data members of the object. It guarantees that calling the function will not change the object's state.

Test
Q.4 Medium OOP Concepts
Which of the following statements about constructors is correct?
A Constructors can have a return type
B Constructors are automatically called when an object is created
C A class can have only one constructor
D Constructors are inherited automatically in all derived classes
Correct Answer:  B. Constructors are automatically called when an object is created
EXPLANATION

Constructors have no return type, a class can have multiple constructors (constructor overloading), and constructors are not automatically inherited in C++ (until C++11 explicit inheritance). They are automatically invoked when objects are created.

Test
Q.5 Medium OOP Concepts
What is the output of the following code?
class A { public: virtual void func() { cout
A A
B B
C C
D Compilation Error
Correct Answer:  C. C
EXPLANATION

With virtual functions, the actual object type (C) determines which function is called, not the pointer type. C::func() is invoked through multilevel inheritance.

Test
Q.6 Medium OOP Concepts
Consider a scenario where a derived class needs to access a base class member that should not be accessible to external code. Which access specifier should be used in the base class?
A public
B protected
C private
D internal
Correct Answer:  B. protected
EXPLANATION

The 'protected' access specifier allows access within the class and derived classes, but not to external code. This is ideal for members that derived classes need to use but external code should not access.

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

Without virtual keyword, function overriding doesn't occur. The pointer type (Base*) determines which function is called, so Base::show() is invoked.

Test
Q.8 Medium OOP Concepts
In which scenario would you use an abstract base class instead of a concrete base class?
A When you want to create many instances of the base class
B When you want to define an interface that derived classes must implement
C When you want faster execution
D When you want to save memory
Correct Answer:  B. When you want to define an interface that derived classes must implement
EXPLANATION

Abstract base classes are used to define interfaces and contracts that derived classes must follow. They cannot be instantiated but force derived classes to implement certain behaviors through pure virtual functions.

Test
Q.9 Medium OOP Concepts
Which of the following is an example of operator overloading as a member function?
A friend ostream& operator
B Class operator+(const Class&);
C operator Class() { return *this; }
D operator==() friend function
Correct Answer:  B. Class operator+(const Class&);
EXPLANATION

Option B shows operator overloading as a member function. The operator is defined as a member function of the class, which takes the second operand as a parameter.

Test
Q.10 Medium OOP Concepts
What is the primary advantage of using virtual functions in a base class?
A To improve compilation speed
B To enable runtime polymorphism and allow derived classes to override behavior
C To reduce memory usage
D To make functions faster
Correct Answer:  B. To enable runtime polymorphism and allow derived classes to override behavior
EXPLANATION

Virtual functions enable runtime polymorphism, allowing the correct derived class method to be called through a base class pointer or reference, facilitating flexible and extensible code design.

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