[NAME] ALL.dao.class.inheritance [TITLE] Inheritance [DESCRIPTION] In Dao, new classes can be derived from existing classes (or C data types) to inherit th eir functionalities and to establish is-a relationship between objects. When a class A is derived from another class B, class A is usually referred to as a child, or derived, or s ub- class, and the class B is ussually referred to as a parent or base class. To derive one class from another, the base class must be placed after the class name of t he derived one separated by a colon. Here is a simple example, 1 class Base 2 { 3 var id = 0 4 5 routine Base( i = 0 ){ id = i } 6 } 7 class Sub : Base 8 { 9 var value = 'abc' 10 } 11 var obj = Sub() In this example, an instance of the derived class is created by calling its implicit defa ult constructor, which will call an constructor (either implicit or explicit) of the deri ved class that accepts no parameters. When defining a constructor of a derived class, the constructor of a base class can be ca lled explicitly, by placing the call right after the constructor signature of the derived on separated by a colon. The call to a base constructor can only accept the parameters ( or the self variable) of the constructor of the derived class. 1 class Sub : Base 2 { 3 var value = 'abc' 4 5 routine Sub( v = 'ABC', i = 3 ) : Base( i ) { value = v } 6 } 1 load meta 2 3 class Base 4 { 5 var id = 0 6 7 routine VirtMeth(){ io.writeln( 'Base::VirtMeth()' ) } 8 routine NormMeth(){ 9 meta.self( self ).VirtMeth() # emulate virtual method call; 10 } 11 } 12 class Sub : Base 13 { 14 var value = 'abc' 15 routine VirtMeth(){ io.writeln( 'Sub::VirtMeth()' ) } 16 } 17 var o : Base = Sub() 18 o.NormMeth() # prints: Sub::VirtMeth()