Unit 5: Dynamic Memory Management and Polymorphism - Subjective Questions

CSE202 — Object Oriented Programming • Practice Questions with Detailed Answers

20 questions

1

Define dynamic memory allocation. Explain the use of the new and delete operators in C++ with an example.

2

Describe how arrays are dynamically allocated and deallocated in C++. Why must delete[] be used instead of delete for a dynamically allocated array?

3

What is a dynamic constructor? Explain how a constructor can allocate memory dynamically, with a suitable C++ example.

4

Explain allocation failure in C++. Compare the throwing and non-throwing forms of the new operator.

5

Define a memory leak. Discuss its causes, effects, detection, and prevention in object-oriented C++ programs.

6

Distinguish between compile-time polymorphism and run-time polymorphism in C++.

7

Explain how function overloading and operator overloading implement compile-time polymorphism. State the important restrictions on overloading.

8

What is a virtual function? Explain how virtual functions support run-time polymorphism in C++.

9

Compare early binding and late binding. Illustrate both forms using C++ member-function calls.

10

Why should a polymorphic base class have a virtual destructor? Explain the consequences of deleting a derived object through a base-class pointer when the base destructor is not virtual.

11

Define a pure virtual function and an abstract class. Explain their syntax, purpose, and important properties.

12

Differentiate between abstract classes and concrete classes. Give a suitable example showing how a concrete class completes an abstract interface.

13

What is a self-referential class? Explain its structure, applications, and limitations with an example.

14

Describe how dynamic memory management is used to create and destroy a singly linked list based on a self-referential class.

15

Analyze the output and binding behavior of the following program. What changes if display() is not declared virtual?

CPP
class Base {
public:
    virtual void display() { cout << "Base"; }
};

class Derived : public Base {
public:
    void display() override { cout << "Derived"; }
};

int main() {
    Derived object;
    Base* pointer = &object;
    pointer->display();
}
16

Explain function overriding in a polymorphic hierarchy. Discuss the roles of matching signatures, virtual, override, and final.

17

A class owns a dynamically allocated array. Explain the problems caused by compiler-generated copying and describe how deep copying and proper resource management solve them.

18

Design an abstract Shape hierarchy containing Circle and Rectangle. Demonstrate pure virtual functions, run-time polymorphism, and safe destruction.

19

Explain dangling pointers, wild pointers, and double deletion. How can these dynamic-memory errors be avoided?

20

Develop and explain a polymorphic employee-management design that dynamically stores different employee types. Your answer should address abstract classes, virtual functions, dynamic allocation, virtual destructors, allocation safety, and memory-leak prevention.