{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ExtendingClasses

ExtendingClasses - setUnits(0 Override toString method of...

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

{[ snackBarMessage ]}