Extends the super class : Inheritance  « Class « Flash / Flex / ActionScript






Extends the super class

 
/*
class ClassName extends SuperClassName {
  // Class definition goes here.
}
*/


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var rBunny:Rabbit = new Rabbit("William", "White and Brown");
        
        trace(rBunny.name);  // Displays: William
        trace(rBunny.coloration);  // Dislays: White and Brown

    }
  }
}

class Mammal {

  var _sName:String;

  public function get name():String {
    return _sName;
  }

  public function set name(sName:String):void {
    _sName = sName;
  }

}

class Rabbit extends Mammal {

  public var _sColoration:String;

  public function Rabbit(sName:String, sColoration:String) {
    _sName = sName;
    _sColoration = sColoration;
  }

  public function get coloration():String {
    return _sColoration;
  }

}

        








Related examples in the same category

1.A Primer on Inheritance
2.Add new method to the children class
3.Three-level inheritance
4.Static Methods and Static Variables Not Inherited
5.Constructor Methods in Subclasses
6.If a subclass does not define a constructor, ActionScript automatically creates one and adds a super call as its only statement.
7.Call super constructor with parameter
8.Class Scope: Code placed at the top-level of a class body resides in that class's scope.
9.You can call the superclass implementation from the subclass implementation using the super keyword to reference the superclass: