Mega Code Archive

 
Categories / Flash ActionScript / Class
 

Overriding Behavior

package{   import flash.display.Sprite;      public class Main extends Sprite{     public function Main(){         var normalGull:Seagull = new Seagull();         var quietGull:Seagull = new QuietSeagull();         normalGull.squawk(); //The seagull says â€˜SQUAAA!'         quietGull.squawk(); //...                  var politeGull:Seagull = new PoliteSeagull(); //A new seagull appears         politeGull.eat();     }   } }      class Seagull     {         public function get weight():Number         {             return 2;         }         public function squawk():void         {             trace("The seagull says 'SQUAAA!'");         }         public function fly():void{                  }         public function eat():void{}     } class QuietSeagull extends Seagull     {         override public function squawk():void         {             trace("...");         }     }      class HungrySeagull extends Seagull     {         override public function get weight():Number         {             return 1.5;         }     }      class PoliteSeagull extends Seagull     {         override public function squawk():void         {             super.squawk();             trace("The shy gull covers his mouth in shame.");         }         override public function fly():void         {             super.fly();             trace("The gull lands and apologizes for blocking out the sun.");         }         override public function eat():void         {             trace("The gull apologizes to the animal it's about to eat.");             super.eat();         }     }