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.
super.methodsuper.makeJourney()super[interface].methodsuper[Travel].comeHome()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".
