13-inheritance - CSE 143 Lecture 13 Inheritance slides...

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

View Full Document Right Arrow Icon
1 CSE 143 Lecture 13 Inheritance slides created by Ethan Apter http://www.cs.washington.edu/143/ 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 1

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

View Full DocumentRight Arrow Icon
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 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 – the new behavior overrides/replaces the old behavior
Background image of page 2
3 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 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 3

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

View Full DocumentRight Arrow Icon
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 8 Extending Object • Consider the class A that we’ve been discussing: public class A { ... } • We didn’t write that A extends anything, but it automatically extends Object : • All the classes you’ve written so far extend Object A B Object This diagram is more complete than before. However, we often don’t
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

13-inheritance - CSE 143 Lecture 13 Inheritance slides...

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

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