SlideShare a Scribd company logo
1 of 77
 
Chapter 15 Inheritance Copyright © 2008 Pearson Addison-Wesley.  All rights reserved.
Overview ,[object Object],[object Object],[object Object],Slide 15-
15.1 Inheritance Copyright © 2008 Pearson Addison-Wesley.  All rights reserved.
Inheritance Basics  ,[object Object],[object Object],[object Object],[object Object],Slide 15-
Employee Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],A Base Class Slide 15-  Display 15.1 Display 15.2
Function print_check ,[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],[object Object],[object Object],Class HourlyEmployee Slide 15-  Display 15.3
Inherited Members ,[object Object],[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],Implementing a Derived Class Slide 15-  Display 15.5
[object Object],[object Object],[object Object],[object Object],Class SalariedEmployee Slide 15-  Display 15.4 Display 15.6 (1-2)
Parent and Child Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Derived Class Types ,[object Object],[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],Derived Class Constructors Slide 15-  Any Employee constructor  could be invoked
Default Initialization ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Private is Private ,[object Object],[object Object],[object Object],[object Object],Slide 15-
The protected Qualifier ,[object Object],[object Object],Slide 15-
Programming Style ,[object Object],[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],[object Object],Redefinition of  Member Functions Slide 15-  Display 15.7 (1-2)
Redefining or Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Function Signatures ,[object Object],[object Object],[object Object],Slide 15-
Access to a  Redefined Base Function ,[object Object],[object Object],Slide 15-
Section 15.1 Conclusion ,[object Object],[object Object],[object Object],Slide 15-
15.2 Inheritance Details Copyright © 2008 Pearson Addison-Wesley.  All rights reserved.
Inheritance Details ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Copy Constructors and  Derived Classes ,[object Object],[object Object],[object Object],Slide 15-
Operator = and  Derived Classes ,[object Object],[object Object],Slide 15-
Destructors and  Derived Classes ,[object Object],[object Object],Slide 15-
The Assignment Operator ,[object Object],[object Object],[object Object],Slide 15-
The Operator = Implementation ,[object Object],[object Object],[object Object],Slide 15-
The Copy Constructor ,[object Object],[object Object],[object Object],Slide 15-
Destructors in Derived Classes ,[object Object],[object Object],[object Object],Slide 15-
Destruction Sequence ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Section 15.2 Conclusion ,[object Object],[object Object],[object Object],Slide 15-
15.3 Polymorphism Copyright © 2008 Pearson Addison-Wesley.  All rights reserved.
Polymorphism ,[object Object],[object Object],Slide 15-
A Late Binding Example ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
A Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Virtual Functions ,[object Object],[object Object],[object Object],Slide 15-
Virtual Functions in C++ ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],[object Object],The Sale Class Slide 15-  Display 15.8 Display 15.9
Virtual Function bill ,[object Object],[object Object],[object Object],Slide 15-
[object Object],[object Object],[object Object],[object Object],DiscountSale::bill Slide 15-  Display 15.10 Display 15.11
Virtual Details ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Overriding ,[object Object],[object Object],Slide 15-
Type Checking ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 15-
Type Checking and Inheritance ,[object Object],Slide 15-
A Sliced Dog is a Pet ,[object Object],[object Object],[object Object],[object Object],Slide 15-
The Slicing Problem ,[object Object],[object Object],[object Object],Slide 15-
Extended Type Compatibility ,[object Object],[object Object],Slide 15-
[object Object],[object Object],Dynamic Variables  and Derived Classes Slide 15-  void Dog::print( ) {   cout << &quot;name: &quot;    <<  name << endl;   cout << &quot;breed: &quot;    << breed << endl; } Pet  *ppet; Dog *pdog; pdog = new Dog;   pdog->name = &quot;Tiny&quot;; pdog->breed = &quot;Great   Dane&quot;; ppet = pdog; Display 15.12 (1-2)
Use Virtual Functions ,[object Object],[object Object],Slide 15-
Why? ,[object Object],[object Object],[object Object],[object Object],Slide 15-
Remember Two Rules ,[object Object],[object Object],[object Object],Slide 15-
Virtual Compilation ,[object Object],[object Object],[object Object],Slide 15-
Virtual Destructors ,[object Object],[object Object],[object Object],[object Object],Slide 15-
Non-Virtual Destructors ,[object Object],[object Object],Slide 15-
Section 15.3 Conclusion ,[object Object],[object Object],[object Object],Slide 15-
Chapter 15 -- End Slide 15-
Display 15.1   Slide 15-  Back Next
Display 15.2 (1/2) Slide 15-  Back Next
Display 15.2 (2/2) Slide 15-  Back Next
Display 15.3 Slide 15-  Back Next
Display 15.4 Slide 15-  Back Next
Display 15.5 (1/2) Slide 15-  Back Next
Display 15.5 (2/2) Slide 15-  Back Next
Display 15.6 (1/2) Slide 15-  Back Next
Display 15.6 (2/2) Slide 15-  Back Next
Display 15.7 (1/2) Slide 15-  Back Next
Display 15.7 (2/2) Slide 15-  Back Next
Display 15.8 Slide 15-  Next Back
Display 15.9 Slide 15-  Back Next
Display 15.10 Slide 15-  Next Back
Display 15.11 Slide 15-  Back Next
Display 15.12 (1/2) Slide 15-  Back Next
Display 15.12 (2/2) Slide 15-  Back Next

More Related Content

Viewers also liked (19)

Savitch Ch 17
Savitch Ch 17Savitch Ch 17
Savitch Ch 17
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Savitch Ch 12
Savitch Ch 12Savitch Ch 12
Savitch Ch 12
 
Savitch Ch 10
Savitch Ch 10Savitch Ch 10
Savitch Ch 10
 
Savitch ch 022
Savitch ch 022Savitch ch 022
Savitch ch 022
 
Savitch c++ ppt figs ch1
Savitch c++ ppt figs ch1Savitch c++ ppt figs ch1
Savitch c++ ppt figs ch1
 
Savitch Ch 18
Savitch Ch 18Savitch Ch 18
Savitch Ch 18
 
Savitch ch 01
Savitch ch 01Savitch ch 01
Savitch ch 01
 
Savitch Ch 01
Savitch Ch 01Savitch Ch 01
Savitch Ch 01
 
Savitch Ch 03
Savitch Ch 03Savitch Ch 03
Savitch Ch 03
 
Savitch Ch 14
Savitch Ch 14Savitch Ch 14
Savitch Ch 14
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
Savitch Ch 11
Savitch Ch 11Savitch Ch 11
Savitch Ch 11
 
Savitch Ch 13
Savitch Ch 13Savitch Ch 13
Savitch Ch 13
 
Savitch Ch 08
Savitch Ch 08Savitch Ch 08
Savitch Ch 08
 
Savitch ch 16
Savitch ch 16Savitch ch 16
Savitch ch 16
 
Savitch Ch 05
Savitch Ch 05Savitch Ch 05
Savitch Ch 05
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

Similar to Savitch Ch 15

How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
Abed Bukhari
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2
Mukul kumar Neal
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
lorindajamieson
 

Similar to Savitch Ch 15 (20)

Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Savitch ch 10
Savitch ch 10Savitch ch 10
Savitch ch 10
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutlet
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
 

More from Terry Yoast

More from Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

Recently uploaded

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Savitch Ch 15