Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 Class Inheritance

Similar presentations


Presentation on theme: "Chapter 11 Class Inheritance"— Presentation transcript:

1 Chapter 11 Class Inheritance

2 Chapter 11 Inheritance is that property of object-oriented programming that allows one class, called a derived class, to share the structure and behavior of another class, called a base class.

3 Chapter 11 A family of bank account classes

4 Chapter 11 The important link between a derived class and its base class is the IS-A link. For instance, a checking account IS-A bank account. The IS-A relationship must exist if inheritance is used properly. If there is no IS-A relationship, inheritance should not be used.

5 Chapter 11 Format for Declaring Derived Classes class derived class : public base class { Derived Class Member Functions Derived Class Member Data }; //END CLASS

6 Chapter 11 A protected member of a class is a member that is accessible to both the base class and any derived classes of the base class in which it is declared. Use the keyword protected when declaring a member of a class if you want to allow access to the member by a derived class. The # symbol is used in UML to denote a protected class member.

7 Chapter 11 An abstract class is a base class for which objects will never be created.

8 Chapter 11 A public base class allows all public members of the base class to be public in the derived class.

9 Chapter 11 Single inheritance occurs when the inherited class members can be traced back to a single parent class. Multiple inheritance occurs when the inherited class members can be traced back to more than one parent class.

10 Chapter 11 Use #ifndef When Declaring Base Classes in C++, as follows: #ifndef HEADER FILE NAME_H #define HEADER FILE NAME _H BASE CLASS DECLARATION #endif

11 Chapter 11 The term polymorphic is Greek meaning “of many forms.” A polymorphic function is one that has the same name for different classes of the same family, but has different implementations, or behavior, for the various classes.

12 Chapter 11 Dynamic, or late, binding occurs when a polymorphic function is defined for several classes in a family but the actual code for the function is not attached, or bound, until execution time. A polymorphic function that is dynamically bound is called a virtual function.

13 Chapter 11 Static binding occurs when a polymorphic function is defined for several classes in a family and the actual code for the function is attached, or bound, at compile time. Overloaded functions are statically bound.


Download ppt "Chapter 11 Class Inheritance"

Similar presentations


Ads by Google