コード例 #1
0
        public static void Main(string[] args)
        {
            Dog dog = new Dog();

            dog.Bark();
            dog.Eat();
            dog.Sleep();

            Dog fido = new Dog("Fido");

            fido.Bark();
            fido.Eat();
            fido.Sleep();

            Console.WriteLine();

            Cat cat = new Cat();

            cat.Purr();
            cat.Eat();
            cat.Sleep();

            Cat garfield = new Cat("Garfield");

            garfield.Purr();
            garfield.Eat();
            garfield.Sleep();

            Console.WriteLine();

            INoiseCapable noisyDog = new Dog();

            noisyDog.MakeNoise();
            INoiseCapable snoopy = new Dog("Snoopy");

            snoopy.MakeNoise();

            INoiseCapable noisyCat = new Cat("Garfield");

            noisyCat.MakeNoise();
            INoiseCapable justCat = new Cat();

            justCat.MakeNoise();

            Cat c = (Cat)noisyCat;

            c.Purr();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Dog dog = new Dog();

            dog.Bark();
            dog.Eat();

            Dog fido = new Dog("Fido");

            fido.Bark();

            Console.WriteLine();

            Cat cat = new Cat();

            cat.Purr();
            cat.Eat();

            Cat garfield = new Cat("Garfield");

            garfield.Purr();

            Console.WriteLine();

            INoiseCapable Dog = new Dog();

            Dog.MakeNoise();

            INoiseCapable Cat = new Cat("Garfield");

            Cat.MakeNoise();

            Cat c = (Cat)cat;

            c.Purr();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Dog dog = new Dog();

            dog.Bark();
            dog.Eat();

            Dog barky = new Dog("Barky");

            barky.Bark();

            Console.WriteLine();

            Cat cat = new Cat();

            cat.Purr();
            cat.Eat();

            Cat fatso = new Cat("Fatso");

            fatso.Purr();

            Console.WriteLine();

            INoiseCapable noisyDog = new Dog();

            noisyDog.MakeNoise();

            INoiseCapable noisyCat = new Cat("Noisy");

            noisyCat.MakeNoise();

            Cat c = (Cat)noisyCat;

            c.Purr();
        }