06-inheritance-binar - CSE 143 Lecture 6 Inheritance binary search reading 9.1 9.3 9.4 13.1 slides created by Marty Stepp

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 143 Lecture 6 Inheritance; binary search reading: 9.1, 9.3 - 9.4; 13.1 slides created by Marty Stepp http://www.cs.washington.edu/143/ Inheritance basics reading: 9.1, 9.3 - 9.4 3 Inheritance • inheritance : Forming new classes based on existing ones. – a way to share/ reuse code between two or more classes – superclass : Parent class being extended. – subclass : Child class that inherits behavior from superclass. • gets a copy of every field and method from superclass 4 Inheritance syntax public class name extends superclass { – Example: public class Lawyer extends Employee { ... } • By extending Employee , each Lawyer object now: – receives a copy of each method from Employee automatically – can be treated as an Employee by client code • Lawyer can also replace ("override") behavior from Employee. 5 The super keyword • A subclass can call its parent's method/constructor: super. method ( parameters ) // method super( parameters ); // constructor – Example: public class Lawyer extends Employee { public Lawyer(String name) { super(name); } // give Lawyers a $5K raise (better) public double getSalary() { double baseSalary = super.getSalary() ; return baseSalary + 5000.00; } } 6 Exercise • Write a class called StutterIntList ....
View Full Document

This note was uploaded on 10/30/2011 for the course COMPUTER S 143 taught by Professor John during the Spring '11 term at Washington State Community College.

Page1 / 14

06-inheritance-binar - CSE 143 Lecture 6 Inheritance binary search reading 9.1 9.3 9.4 13.1 slides created by Marty Stepp

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

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