RU beehive logo ITEC dept promo banner
ITEC 120
2008fall
aaray,
ejderrick,
ibarland,
jmdymacek

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive

lect14b
Inheritance

We've seen class Dog, where every Dog has a sound, and a method speak (which repeats that sound twice). What if we had other animals we wanted to model? Say, cats and pythons, which both had those same behaviors? However, we will still want separate classes, since some activities are specific to Dogs (like ageInDogYears()).

One solution would be lots of repeated code for speak. But (for the first time)1 we'll see what object-oriented programming buys for us: the ability to share code between different (related) classes.


1Every single method we've written this semester could have been made static! We would just have to make one change to each method: add another parameter -- named this. Then when calling the method, rather than saying jo.setSalary(12.00), we'd just have called setSalary(jo, 12.00). With this simple transformation, we could have done everything this semester without ever needing methods inside of a class (though we'd still need fields inside objects).      

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Dec.10 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme