ExtendingClasses

ExtendingClasses - setUnits(0); } // Override toString...

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

View Full Document Right Arrow Icon
• Build classes that extend functionality of existing class • Say we want to define Frosh as a subclass of Student – Frosh have all the same properties as Students – Frosh start with 0 units – We specially designate "Frosh" in string display of object • Just because your RAs love you! Extending Classes public class Frosh extends Student { public Frosh(String name, int id) { super(name, id); // calls Student constructor
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: setUnits(0); } // Override toString method of Student public String toString() { // studentID and studentName are private, // so they are not directly accessible, even // in subclass! Must use public "getters". return ("Frosh: " + getName() + " (#" + getID() + ")"); } } • Everything else is inherited from Student Extending Classes...
View Full Document

This note was uploaded on 10/25/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online