override method from parent class : Override « Class « Flash / Flex / ActionScript






override method from parent class

 

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

        
        var c:Cat = new Cat();
        c.speak("Miao");
    }
  }
}
     class Animal {
          public function Animal() {
          }
          public function speak(sound:String):void {
               trace(sound);
          }
     }
     class Cat extends Animal {
          public function Cat() {
          }
          public override function speak(sound:String):void {
               for (var i:uint=0; i < 100; i++) {
                    super.speak("Meow! Meow! Meow!");
               }
          }
     }

        








Related examples in the same category

1.Overriding Instance Methods
2.Invoking an Overridden Instance Method: super.methodName(arg1, arg2, ...argn);
3.Overriding Behavior