Chapter 18 C Inheritance and Polymorphism - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter 18 C Inheritance and Polymorphism

Description:

derived class is public, most popular, used here. every non ... Slide 15. Inherited Class (Cont.) Example: Tetrahedran class. tetrahedran.h. tetrahedran.cpp ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 23
Provided by: radf7
Category:

less

Transcript and Presenter's Notes

Title: Chapter 18 C Inheritance and Polymorphism


1
Chapter 18 C Inheritance and Polymorphism
  • By C. Shing
  • ITEC Dept
  • Radford University

2
Objectives
  • Understand how to create abstract class
  • Understand how to use inheritance
  • Understand how to use polyporphism

3
Inheritance
  • Inheritance tree
  • Parent super-class (base class), larger set of
    objects,
  • general functions
  • Child sub-class (derived class),
  • subset of parent objects, special functions
  • Parent class-child class relationship
  • child object is a parent object

4
Types of Inheritance
  • 3 types of inheritance
  • Public
  • derived class is public, most popular, used here
  • every non-member class can access
  • derived public functions
  • Protected derived classes are protected classes
  • Only member function can access those functions
  • Private derived classes are private classes
  • Only member function can access those functions

5
Public Inheritance Implementation
  • Inheritance implementation
  • Form
  • class child_class public parent_class
  • Public
  • Private

6
Inheritance Example
7
Inheritance Example (Cont.)
Circle
8
Inheritance Example (Cont.)
9
Inheritance Example (Cont.)
10
Abstract Class
  • The class includes only all specification
  • No implementation

11
Abstract Class (Cont.)
  • Example Geometry class
  • geometry.h

12
Inherited Class
  • Example Point class
  • point.h
  • point.cpp

13
Inherited Class (Cont.)
  • Example Line class
  • line.h
  • line.cpp

14
Inherited Class (Cont.)
  • Example Triangle class
  • triangle.h
  • triangle.cpp

15
Inherited Class (Cont.)
  • Example Tetrahedran class
  • tetrahedran.h
  • tetrahedran.cpp

16
Inherited Class (Cont.)
  • Example Rectangle class
  • rectangle.h
  • rectangle.cpp

17
Inherited Class (Cont.)
  • Example Parallelgram class
  • parallelgram.h
  • parallelgram.cpp

18
Inherited Class (Cont.)
  • Example Circle class
  • circle.h
  • circle.cpp

19
Polymorphism
  • Decide data type of the class during run-time
  • in inheritance tree.

20
Polymorphism (Cont.)
  • Example
  • polymorphism.cpp

21
Polymorphism (Cont.)
  • Example whole program
  • polymorphism_whole.cpp

22
References
  • Deitel Deitel C How to Program, 4th ed.,
  • Chapter 19 20, Prentice Hall
Write a Comment
User Comments (0)
About PowerShow.com