Overriding Behavior : Override « Class « Flash / Flex / ActionScript

Home
Flash / Flex / ActionScript
1.Animation
2.Array
3.Class
4.Data Type
5.Development
6.Function
7.Graphics
8.Language
9.Network
10.Regular Expressions
11.Statement
12.String
13.TextField
14.XML
Flash / Flex / ActionScript » Class » Override 




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();
        }
    }
    

        














Related examples in the same category
1.Overriding Instance Methods
2.Invoking an Overridden Instance Method: super.methodName(arg1, arg2, ...argn);
3.override method from parent class
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.