COM SCI 32 Lecture Notes - Lecture 8: In C, Virtual Function, Batmobile

45 views22 pages

Document Summary

Inheritance is a way to form new classes using classes that have already been identi(cid:210)ed. Inheritance is the basis of all objected oriented programming. Let"s consider the robot class: class robot public: void setx(int newx); int getx(); void sety(int newy); int gety(); private: int m_x, m_y; Now let"s consider the shielded robot class: class shieldedrobot public: void setx(int newx); int getx(); void sety(int newy); int gety(); int getshield(); void setshield(int s); private: int m_x, m_y, m_shield; Both classes have x and y coordinates and provide the same set of methods to get and set the values of x and y. A shielded robot is a kind of robot! It shares all of the same methods and data as a robot. C++ lets us de(cid:210)ne a new class and have it inherit all of the methods/data of an existing, related class.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers