Computer Science 1037A/B Lecture 42: Composition Versus Inheritance

28 views1 pages

Document Summary

Inheritance models an "is a" relation between classes. An object of a derived class "is a(n)" object of the base class. Example: an undergrad is a student a mammal is an animal a poodle is a dog. Composition is appropriate when the new class needs to use an object of an existing class. Inheritance is appropriate when objects of the new class are a subset of the objects of the existing class objects of the new class will be used in the same ways as the objects of the existing class. In inheritance, when an instance of the derived class is created, the constructor of the base class will be called first, then the constructor of the derived class. However, when an object of a derived class is destroyed, the destructor of the derived class will be called first.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions