Overriding Instance Methods : Override « Class « Flash / Flex / ActionScript






Overriding Instance Methods

 
 
ActionScript 3.0 allows instance methods to be redefined but not instance variables, static variables, or static methods.


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

        var aInstance = new A(  );
        aInstance.m();  // Displays: A's m(  ) was called
        
        var bInstance = new B(  );
        bInstance.m();  // Displays: B's m(  ) was called

    }
  }
}
class A {
  public function m (  ) {
    trace("A's m(  ) was called");
  }
}
class B extends A {
  // Override the superclass's method m(  )
  override public function m (  ) {
    trace("B's m(  ) was called");
  }
}

        








Related examples in the same category

1.Invoking an Overridden Instance Method: super.methodName(arg1, arg2, ...argn);
2.override method from parent class
3.Overriding Behavior