1 / 6

Inheritance

Inheritance. What is it?. Inheritance can be thought of as software reusability where one class inherits another classes' data & methods and adds new functionality of its own Parts: base class - the existing class derived class - the new class with inherited members and additional behaviors.

buzz
Télécharger la présentation

Inheritance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inheritance CS250 Introduction to Computer Science II

  2. What is it? • Inheritance can be thought of as software reusability where one class inherits another classes' data & methods and adds new functionality of its own • Parts: • base class - the existing class • derived class - the new class with inherited members and additional behaviors CS250 Introduction to Computer Science II

  3. Inheritance • Three kinds of inheritance exist in C++: • Public • Protected • Private CS250 Introduction to Computer Science II

  4. Public Inheritance • Every derived class object is also an object of the base class. • As an example, if the base class is "Vehicle" then a derived class might be "Cars" and "Trucks." Cars inherit the members and behaviors of a Vehicle and add other behaviors and members • Members of a derived class cannot directly access the private members of a base class CS250 Introduction to Computer Science II

  5. Examples of Inheritance • I would like to examine examples in the following order: • 1. Fig 9.4 on p. 615 (point.h) • 2. Fig 9.5 on pp. 616-617 (point.cpp) • 3. Fig 9.6 on p. 617 (pointtest.cpp) • 4. Fig 9.7 on p. 618 (circle.h) • 5. Fig 9.8 on pp. 619-620 (circle.cpp) • 6. Fig 9.9 on p. 621 (circletest.cpp) • 7. Fig 9.10 on pp. 622-623 (circle2.h) • 8. Fig 9.11 on pp. 623-624 (circle2.cpp) • 9. Fig 9.12 on p. 625 (point2.h) • 10. Fig 9.13 on pp. 625-626 (point2.cpp) • 11. Fig 9.14 on pp. 627 (circle3.h) • 12. Fig 9.15 on pp. 627-628 (circle3.cpp) • 13. Fig 9.16 on pp. 629-630 (circletest3.cpp) CS250 Introduction to Computer Science II

  6. Summary • We discussed inheritance • We covered: • Pages 610 - 630 CS250 Introduction to Computer Science II

More Related