static void Main(string[] args)
        {
            Duck myduck = new MallardDuck();

            myduck.display();
            myduck.performFly();
            myduck.performQuack();

            myduck = new RedHeadDuck();
            myduck.display();
            myduck.performFly();
            myduck.performQuack();

            myduck = new RubberDuck();
            myduck.display();
            myduck.performFly();
            myduck.performQuack();

            myduck = new DecoyDuck();
            myduck.display();
            myduck.performFly();
            myduck.performQuack();

            myduck.setFlyBehavior(new FlyJet());
            myduck.performFly();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //try
            //{

                RedHeadDuck redHead = new RedHeadDuck();
                redHead.display();
                redHead.setFlyBehavior(new FlyWithRockets());// Learned from experience. This line takes care of error "Additional information: Object reference not set to an instance of an object." for performFly().
                redHead.performFly();
                Console.ReadLine();
            //}

            /*catch (NullReferenceException nre)
            {
                Console.WriteLine(
                 "\nCan't call BarMethod(), foo is null.\n" +
                 nre.Message);
            }*/
        }
Exemple #3
0
        static void Main(string[] args)
        {
            //try
            //{

            RedHeadDuck redHead = new RedHeadDuck();

            redHead.display();
            redHead.setFlyBehavior(new FlyWithRockets());    // Learned from experience. This line takes care of error "Additional information: Object reference not set to an instance of an object." for performFly().
            redHead.performFly();
            Console.ReadLine();
            //}

            /*catch (NullReferenceException nre)
             * {
             *  Console.WriteLine(
             *   "\nCan't call BarMethod(), foo is null.\n" +
             *   nre.Message);
             * }*/
        }