lec22 - Lecture 22 More on Inheritence(Savitch 7.1 CS125...

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

View Full Document Right Arrow Icon
CS125 Course Notes Lecture 22, Slide 1 Lecture 22 •More on Inheritence (Savitch 7.1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 22, Slide 2 The Dog class Let’s improve the Dog class: public class Dog extends Mammal { private String owner; // *** new instance variable *** public Dog() { super(); this.owner = "No owner yet."; this.setSound(""); } public Dog(String name, String theOwner) { super(name, false, "Woof!"); this.owner = theOwner; } // The rest of the class unchanged }
Background image of page 2
CS125 Course Notes Lecture 22, Slide 3 Accessing the parent class • Now we want to add an equals method as before to override the Mammal one. • But don’t want to redo method from scratch. • Want to access the Mammal method equals from within the Dog class.
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 22, Slide 4 Accessing the parent class continued • Using super as the name of the object will use the method defined in the parent (base) class. • Similar to this , but pretends it is an instance of the parent class.
Background image of page 4
Course Notes Lecture 22, Slide 5 The equals method of the Dog class So we can add the following method:
Background image of page 5

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

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

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 20

lec22 - Lecture 22 More on Inheritence(Savitch 7.1 CS125...

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

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