So we may override a method in a subclass using the

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: hen we specialize (i.e., create subclasses), we may want to restrict or modify the methods of the parent class for this particular subclass. • So we may override a method in a subclass using the same signature as the super class method, but replacing the body of the method. CS133 Course Notes Lecture 14, Slide 19 Co-op Student • Suppose we extend the Student class to a subclass Co-op student. – Co-op students may be on a work term, or oncampus – Co-op students pay an additional Co-op fee CS133 Course Notes Lecture 14, Slide 20 19 20 The CoopStudent class public class CoopStudent extends Student { private boolean isOnWorkTerm = false; private static final double COOP_FEE = 317.69; public CoopStudent(String newName, int sID) { super(newName, sID); } public CoopStudent(String newName, String newAddress, int sID) Override { super(newName, newAddress, sID); calcFees } public double calcFees() { return super.calcFees() + COOP_FEE; }...
View Full Document

This note was uploaded on 07/17/2010 for the course CS 133 taught by Professor Kierstead during the Fall '07 term at Waterloo.

Ask a homework question - tutors are online