" CS 1621 Fall 2005 Example of a subclass in Smalltalk. " Person subclass: #Student instanceVariableNames: 'major gpa' classVariableNames: '' poolDictionaries: '' ! !Student class methods ! ! !Student methods ! " Here we first call the superclass version of the method to utilize its reading functionality, then we read the last two fields in here. Note that because subclasses have direct access to superclass instance variables in Smalltalk, we could have read them in directly here, but why do that when it is already done by the superclass?" getData | s | super getData. s := Prompter prompt: 'Major? ' default: ''. major := s. s := Prompter prompt: 'GPA? ' default: ''. gpa := (s asNumber) asFloat. ^self! major "return major of receiver student" ^major! gpa "return gpa of receiver student" ^gpa! " First call super version os printString then append the rest to the end of it" printString | w | w := WriteStream on: String new. w nextPutAll: (super printString) ; nl; nextPutAll: 'Major: ' ; nextPutAll: major ; nl ; nextPutAll: 'GPA: '. gpa printOn: w. w nl. ^(w contents)! !