CSC 1061 Week 06 Inheritance PDF
Document Details
Uploaded by DivineZebra9695
Red Rocks Community College
Tags
Summary
This document is lecture notes for a course on inheritance and polymorphism in C++. It covers topics such as inheritance, polymorphism and multiple inheritance. The document also includes review questions and demos.
Full Transcript
CSC 1061 INHERITANCE AND POLYMORPHISM OBJECTIVES AGENDA: WEEK 06 Recognize situations in which 1. Review check inheritance can simplify the 2. Class "has a" | Inheritance "is a" implementation of a group of related classes 3. Sin...
CSC 1061 INHERITANCE AND POLYMORPHISM OBJECTIVES AGENDA: WEEK 06 Recognize situations in which 1. Review check inheritance can simplify the 2. Class "has a" | Inheritance "is a" implementation of a group of related classes 3. Single Inheritance Implement a derived class 4. Why, What, How: C++ Inheritance Recognize situations in which 5. Demo: Record is a std::string creating an abstract base class 6. Multiple Inheritance will allow the later implementation of many 7. Polymorphism derived classes that share underlying functions. REVIEW CHECK Complete the multiple-choice questions 1 to 5 10.11.1. Easier Multiple-Choice Questions CLASS "HAS A" RELATIONSHIP Classes are the blue-prints for Abstract Data Types (ADT) A class "has a" data member relationship Classes encapsulate data and functionality Composition is when a class has a data members that is an object: Player has a name that is a std::string INHERITANCE "IS A" RELATIONSHIPS Grandparent Shape Parent Polygon Child Rectangle Triangle SINGLE INHERITANCE Base, Update with Parent, Super your own real-world example of a single inheritance Derived, situation Child, Sub WHY USE INHERITANCE Code ReUSE! Complete the multiple-choice questions 2 and 3. The other multiple-choice questions are Java specific and not relevant for C++. WHAT IS INHERITED FROM BASE CLASS In principle, a publicly derived class inherits access to every member of a base class except: constructors: ClassName(); destructor: ~ClassName(); assignment operator member: operator= friend non-member functions: , ==, !=, >, =,