[Next] [Previous] [Up] [Top] [Contents] [Index]

Methods

Creating subclasses and specializing their methods

When you create a subclass, you can write methods specific to that subclass.

? (defclass shy-kid (fourth-grader)())
#<STANDARD-CLASS SHY-KID>
? (defmethod say ((child shy-kid) sentence)
    (princ "...")
    (princ sentence)
    (princ "...")
    (terpri))
#<Method SAY (SHY-KID T)>
? (setq max (make-instance 'shy-kid))
#<SHY-KID #x609A69>
? (say max "Hi")
...Hi...
NIL

An instance of a subclass still inherits slot values and methods from its class's superclasses.

? (school max)
"Lawrence School"


Gettmg Started with MCL - 19 OCT 1996
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker