Inheritance

When defining a new class, all the member attributes of an existing class can be inherited. The existing and the new class are called super and sub classes respectively.

The super class of a sub class is specified in the sub class definition by setting the super collective attribute to a value. For example:

   global.person =   class
                       public name = "???";
                       public dob = "???";
                       public gender = "F";
                       ...
                     end

   global.student =  class
                       ...
                       super = person
                     end

Here person should be a value visible in the surrounding scope of the definition of student class. Usually it should be a globally defined class name. To avoid potential name clashes, one can use

	super = global.person

Now student is a sub class of person, all attributes defined for person will be created for any member of student as well. For example

   >> s = student.new();
   >> s.name  // check s's name, which is inherited from 'person'
   >> s.dob   // check s's dob, which is inherited from 'person'
There is no language facility provided for calling the constructor of the super class automatically. The sub class needs to write a constructor to handle the initialization of the inherited attributes.



oz 2009-12-22