Lecture 7 - Inheritance, Day 1


As usual, create a directory to hold today's activities:

$ mkdir ~/cs170/labs/lab7
$ cd ~/cs170/labs/lab7

Class Structures

Hand in your class structures at the beginning of class. And remember, now is not the time to be working on it. I will look at them this evening, and upload comments to inquire by tomorrow.


Quiz

Let's make these Wednesday quizzes a regular event. This quiz will be only on classes and objects. We'll worry about Inheritance for next week. So, be prepared for a Quiz at the beginning of class on Wednesday.


Inheritance

We now have a mechanism to create our own data types, which is pretty neat. One of the major benefits to this is reusability of code. However, there are some instances where your current knowledge of classes would cause your code to not be reusable in certain circumstances. For example, when something doesn't fit directly into the templates we have created for an object. Let's see how inheritance can alleviate that for us today.


Lab Activity 1
Dogs

One of the more classical examples of Inheritance is describing animals. There is a well known hierarchy of animals, based off of genus, species, phylum, etc. However, that can be a little bit complicated and overwhelming. So, we'll focus on one common type of animal: dogs.

This is a very simplistic, directed, and less that useful example of inheritance. Hopefully it give you an intuition as far as the syntax and the meaning behind inheritance.

Details

  1. The file