Unit 4: Operator Overloading, Type Conversion and Inheritance - Subjective Questions

CSE202 — Object Oriented Programming • Practice Questions with Detailed Answers

20 questions

1

Define operator overloading. Explain its purpose and state the important rules that govern operator overloading in C++.

2

Explain unary operator overloading in C++. Illustrate how the unary minus operator can be overloaded using a member function.

3

Distinguish between prefix and postfix increment operator overloading. Write suitable C++ implementations for both forms.

4

Describe binary operator overloading. Show how the + operator can be overloaded to add two complex numbers.

5

Compare overloading a binary operator using a member function and a friend function. When is a friend function preferable?

6

Explain the conversion of a basic type to a class type using a conversion constructor. Give a suitable example.

7

Explain the conversion of a class type to a basic type using a conversion function. State the syntax and restrictions of such a function.

8

Define inheritance, base class, and derived class. Explain simple inheritance with a C++ example.

9

Describe multilevel inheritance. Explain the accessibility of inherited members through different levels with an example.

10

What is multiple inheritance? Explain its advantages and potential problems using a suitable class structure.

11

Explain hierarchical inheritance and distinguish it from multilevel inheritance.

12

Compare public, protected, and private inheritance in C++. Explain how each mode affects the accessibility of base-class members.

13

Explain member-function overriding in inheritance. How does it differ from function overloading and function hiding?

14

Describe the order of execution of constructors and destructors in single, multilevel, and multiple inheritance.

15

What causes ambiguity in multiple inheritance? Explain different methods of resolving ambiguous member references.

16

Explain the diamond problem in inheritance. How does a virtual base class solve it?

17

Define aggregation and explain how it represents a weak whole-part relationship. Give an example.

18

Define composition and explain how object lifetime and ownership are handled in a composition relationship.

19

Compare aggregation and composition with respect to ownership, lifetime, sharing, and implementation.

20

Design and explain a C++ class hierarchy that demonstrates multiple inheritance, ambiguity resolution, virtual inheritance, overriding, and constructor order.