Extending another class to make a subclass

You can extend another class to inherit methods, fields, and properties from a parent class by using the extends keyword after your class name, followed by the parent class name. For example:

class Tree extends Plant {
}

Your class is a subclass and subtype of the parent class. The parent class is a superclass and supertype of your class.

When subclassing a parent class or implementing an interface, you can override the methods defined in the parent class or interface.

To call the method that a parent class defines, use the super keyword using the following syntax:
super.method
For example, if a parent class defines a no-argument method makeJourney, the subclass can call the parent implementation like the following line:
super.makeJourney()
To call a default method that an interface defines, use the super keyword using the following syntax:
super[interface].method
For example, if an interface Travel defines a no-argument method comeHome that contains default code, the implementing class can call the default implementation like the following line:
super[Travel].comeHome()
Note: When overriding the equals method for objects, which is a common technique for overriding the == operator, you must also override the hashCode method. You must use logic ensuring that the return value for a.equals(b) always matches the return value for a.hashCode() == b.hashCode().

In the following example, the Plant class is the parent of the Tree subclass:

class Plant {
  var _type = ""
  property get Type() : String {
    return _type
  }
  property set Type(value:String) : void {
    _type = value
  }
}

class Tree extends Plant {
  override property set Type(value:String) : void {
    _type = "Plant type: " + value
  }
}

In this example, if myPlant is an object of type Plant, running myPlant.Type = "sunflower" sets the private variable _type to "sunflower".

If myTree is an object of type Tree, which has overridden the Plant.Type property setter, running myPlant.Type = "sunflower" sets the private variable _type to "Plant type: sunflower".