13-inheritance - CSE143 Lecture13 Inheritance...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143 Lecture 13 Inheritance slides created by Ethan Apter http://www.cs.washington.edu/143/
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Intuition: Employee Types Consider this (partial) hierarchy of employee types: What kind of tasks can each employee type perform? Employee Clerical Professional Secretary Legal Secretary Lawyer Engineer
Background image of page 2
3 Intuition: Employee Types What tasks should  all  employees be able to do? show up for work work collect paychecks What tasks can a lawyer do that an engineer cannot? sue file legal briefs Which kind of secretary (regular or legal) can accomplish        a  greater variety of tasks? legal secretaries can do all regular secretarial work and           have special training for additional tasks
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Intuition: Employee Training On your first day at work, you’ll likely receive some        general  training for your new job If it’s a big company (like Microsoft), you’ll likely receive      this  with many other types of employees engineers, business people, lawyers, etc After this general training, you’ll probably receive some  specialized training “I know yesterday they told you to fill out your time-card on     the  white sheet, but here we do it online instead” We call this kind of replacement  overriding
Background image of page 4
5 Inheritance Overview Java does something similar with inheritance If we want to show an inheritance relationship between       two  classes, we use the  extends  keyword: public class B extends A { ... } Which sets up the following inheritance hierarchy: A B superclass subclass
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Superclasses and Subclasses In the previous example,  A  is the  superclass  of  B  ( A  is above  B   on the hierarchy), and  B  is a  subclass  of  A  ( B  is below  A  on the  hierarchy) This wording is somewhat different from standard English: So, a “super bacon cheeseburger” is just a hamburger that doesn’t seem right: it’s missing bacon and cheese! but that’s how inheritance works  hamburger bacon cheeseburger superclass subclass
Background image of page 6
7 Base and Derived Classes We also say  A  is the  base class  of  B , and  B  is a           derived  class  of  A This makes a little more sense: A hamburger provides the basic form of a bacon    cheeseburger.  Alternatively, a bacon cheeseburger is a  hamburger with minor additions hamburger bacon cheeseburger base class derived class
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Extending  Object Consider the class  A  that we’ve been discussing: public class A { ... } We didn’t write that 
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/29/2010 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Page1 / 33

13-inheritance - CSE143 Lecture13 Inheritance...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online