[Newbies] Question about inheritance

Mathieu mathk.sue at gmail.com
Fri Oct 13 14:29:25 UTC 2006

dennis petrocelli a écrit :
> Greetings smalltalkers,
> I'm a newbie trying to get my head around inheritance.  I'm puzzled by
> the following example.  It seems to do what I mean, but not what I type
> ;)  This is a good thing, but I'd get further if I understood the
> semantics a bit better.
> from
> http://www.cosc.canterbury.ac.nz/wolfgang.kreutzer/cosc205/smalltalk1.html
> Class: Monster
> Superclass: Object
> Category: Sesame Street
> Instance variables: colour tummy
> initialization
> initialize
>    self colour: #green.
> self tummy: Bag new
> "There is only a single class method and no class variables."
> creation
> new
>    ^ super new initialize
> What I don't understand is this:  Monster new returns an instance of
> Monster, what you'd want it to. But Monster new executes "^ super new"
> which to my mind should return an instance of Object, not Monster.  Just
> to confuse myself further, I typed:
> Monster superclass new
> and got an Object.  It seems to me that "super new" and "superclass new"
> should do the same thing.
> Any points to clarify my confusion would be greatly appreciated.

This is beceause (super = self) it's only in term of lookup that super is different.
super and self represent the receiver. so 'super new' call new from Object but with the knowlege
that he have to build a Monster object.

#superclass is an method and weusally writ it with a '#' in front of it. so you can't compare super
and a method (super is an object, super = self).
So #superclass give you the object supercass of your Monster (ie Object)

> Thanks,
> Dennis Petrocelli 

More information about the Beginners mailing list