Inheritance Preparation
Overview
Sometimes, you want to have two (or more) classes that share a lot of similar attributes but differ in key ways. There are multiple programming solutions to this situation (other than copy and paste!), but one that we’ll focus on today is inheritance. You may or may not have seen this previously, so I’m assuming you haven’t.
Basic Learning Objectives
Before class, you should be able to:
- Explain the idea of inheritance in programming
- Identify the C++ syntax for creating a derived class
- Identify the C++ syntax for calling the methods of a derived class
Advanced Learning Objectives
After class, you should be able to:
- Create your own base and derived classes
Resources
You can use the following resources (there are lots of other good ones out there):
- W3Schools Inheritance
- W3Schools Polymorphism
Checks
Submit answers to the following on Moodle:
- If I have a base class
Organism
, what is the syntax for creating a derived classPredator
? - If my base class
Organism
has a public methodmove
, what is the syntax for creating aPredator
object and calling themove
method?