Contents | < Browse | Browse >
14E. Constructors, Destructors and Super-Methods
The constructor name may be anything, but it is usually given the same name
as the class. One may even have multiple constructors for one class.
A constructor is called directly on the object created with NEW (and only
Destructors however have to be named "end". An object is destroyed like this:
If 'obj' has a .end() method, it is automatically called. end() shouldn't have
any arguments, and it is of no use returning a value. (see 5M for a desciption
of END's precise functioning).
The super-method of a method is the method by the same name of its super
class. Sometimes it's handy to call this method because you might want to
add its behaviour to the implementation of your class, however, since
you're redefined it, calling the super-method by that name will just
call yourself (!). The SUPER keyword allows you to call any method of your
superclass (or someone else's superclass):
This piece of code above can be used as expression and statement.
Care has to be taken though, since if your supermethod calls another
method of that object, it will call the redefined version, not the
one at its own 'level', so to speak (generally this is what one wants).
Also, the compiler looks at the static type of 'obj' to find the
superclass, not the dynamic type (though it may still have that behaviour).