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 21–30 of 49
Topics in C++ Programming
All OOP Concepts 100
Q.21 Medium OOP Concepts
What is the purpose of using static members in a class?
A To prevent inheritance
B To share data among all objects of the class
C To make members read-only
D To improve performance
Correct Answer:  B. To share data among all objects of the class
EXPLANATION

Static members belong to the class, not to individual objects. All objects of the class share the same static member, making it useful for counters, constants, etc.

Test
Q.22 Medium OOP Concepts
Which statement about 'this' pointer is correct?
A It points to the base class
B It points to the current object
C It is optional in all methods
D It stores memory address of the class
Correct Answer:  B. It points to the current object
EXPLANATION

The 'this' pointer is an implicit pointer that points to the current object. It is automatically available in non-static member functions.

Test
Q.23 Medium OOP Concepts
What is 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 the virtual keyword, static binding occurs. The function called is determined by the pointer type (Base*), not the actual object type. Output is 'Base'.

Test
Q.24 Medium OOP Concepts
In C++, what is the default access specifier for class members?
A public
B protected
C private
D internal
Correct Answer:  C. private
EXPLANATION

In C++, the default access specifier for class members is private. For structs, it is public.

Test
Q.25 Medium OOP Concepts
Which of the following statements about constructors in C++ is FALSE?
A Constructors can be overloaded
B Constructors can have return type void
C Constructors are called automatically when an object is created
D Constructors can be private
Correct Answer:  B. Constructors can have return type void
EXPLANATION

Constructors do not have a return type, not even void. They are special member functions that automatically initialize objects when created.

Test
Q.26 Medium OOP Concepts
In C++11 and later, what does the 'override' keyword ensure when used with virtual functions?
A The function will definitely override the base class function
B Compilation error if the function doesn't actually override a base class virtual function
C The function becomes non-virtual
D The function is protected from external access
Correct Answer:  B. Compilation error if the function doesn't actually override a base class virtual function
EXPLANATION

The 'override' keyword (C++11) provides compile-time checking to ensure that a function actually overrides a virtual function from the base class.

Test
Q.27 Medium OOP Concepts
In C++, what is a friend function?
A A function that belongs to multiple classes
B A function external to a class that has access to its private and protected members
C A virtual function declared in the base class
D A static function that cannot be overridden
Correct Answer:  B. A function external to a class that has access to its private and protected members
EXPLANATION

A friend function is declared using the 'friend' keyword and can access private and protected members of the class, breaking encapsulation when necessary.

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

Since func() is virtual and ptr points to a B object, B::func() is called due to dynamic dispatch, printing 'B'.

Test
Q.29 Medium OOP Concepts
Which of the following is NOT a type of polymorphism in C++?
A Compile-time Polymorphism
B Runtime Polymorphism
C Memory Polymorphism
D Parametric Polymorphism
Correct Answer:  C. Memory Polymorphism
EXPLANATION

Memory Polymorphism is not a recognized type of polymorphism in C++. The main types are compile-time (static), runtime (dynamic), and parametric polymorphism.

Test
Q.30 Medium OOP Concepts
What is the purpose of a destructor in C++?
A To initialize object members
B To release resources allocated to an object
C To prevent object copying
D To enforce access restrictions
Correct Answer:  B. To release resources allocated to an object
EXPLANATION

A destructor is called when an object is destroyed, allowing cleanup of dynamically allocated memory and other resources.

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