7
INHERITANCE: EXTENDING CLASSES
7.1 INTRODUCTION TO CODE REUSE
Almost all programming languages support functions that allow a piece of code to be reused again and again in a calling program. However, functions provide rather limited support for code reuse. In object-oriented programming (OOP), code reuse is a central feature. In fact, we can reuse the code written in a class in another class by either of the two mechanisms given below:
- Containership
- Inheritance
7.2 CONTAINERSHIP
In day-to-day life, we come across objects which are composed of other objects. For instance, a computer is composed of objects like motherboard, hard disk, CD-ROM drive, monitor, etc. The motherboard contains a CPU and other components. The CPU contains ALU, CU and ...
Get Object-Oriented Programming with C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.