Unit 4: Operator Overloading, Type Casting and Re-usability - Subjective Questions

CAP455 — Object Oriented Programming Using C++ • Practice Questions with Detailed Answers

20 questions

1

Define operator overloading in C++. Why is it important in object-oriented programming?

2

Explain how a unary operator is overloaded using a member function. Illustrate your answer by overloading unary minus for a class.

3

Differentiate between the prefix and postfix forms of overloaded increment operator ++. Explain with suitable function declarations.

4

Describe the overloading of a binary operator using both a member function and a non-member friend function.

5

Write and explain a C++ class that overloads the binary + operator to add two complex numbers.

6

State the major rules and restrictions associated with operator overloading in C++.

7

Explain basic type to class type conversion using a converting constructor. Give an appropriate example.

8

Explain class type to basic type conversion using a conversion function. Illustrate conversion of a class object to double.

9

Compare basic-to-class and class-to-basic type conversions in C++.

10

What is inheritance? Explain its role in software re-usability and identify the base class and derived class.

11

Explain simple inheritance and multilevel inheritance with suitable class relationships.

12

Describe multiple inheritance. Discuss its advantages and possible ambiguity problems.

13

Explain hierarchical inheritance and hybrid inheritance with examples.

14

Compare public, protected, and private modes of inheritance in C++.

15

Distinguish between private members, protected members, and the private mode of inheritance.

16

What is member function overriding? Differentiate it from function overloading and explain the role of virtual and override.

17

Explain the order of execution of constructors and destructors in simple, multilevel, and multiple inheritance.

18

How are member-name ambiguities resolved in multiple inheritance? Explain using the scope resolution operator.

19

What is a virtual base class? Explain how it solves the diamond inheritance problem.

20

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