A Primer on Inheritance : Inheritance  « Class « Flash / Flex / ActionScript






A Primer on Inheritance

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        var aInstance = new A(  );
        aInstance.m();       // Displays: Method m(  ) was called
        trace(aInstance.v);  // Displays: 10
        var bInstance:B = new B(  );
        bInstance.m();       // Displays: Method m(  ) was called
        trace(bInstance.v);  // Displays: 10
        
    }
  }
}

class A {
  public var v = 10;

  public function m (  ) {
    trace("Method m(  ) was called");
  }
}
class B extends A {
}

Method m(  ) was called
10
Method m(  ) was called
10

        








Related examples in the same category

1.Extends the super class
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: