Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Nhap con vat ban muon chon: ");
            int x = Convert.ToInt32(Console.ReadLine());

            switch (x)
            {
            case 1:
                Console.WriteLine("Bạn đã chọn mèo");
                DongVat meo = new Cat();
                Console.WriteLine("Tiếng mèo kêu: ");
                meo.speak();
                Console.WriteLine("Di chuyển mèo: ");
                meo.move();
                Console.WriteLine("Mèo ăn: ");
                meo.eat();
                break;

            case 2:
                DongVat chim = new Bird();
                Console.WriteLine("Bạn đã chọn chim:");
                Console.WriteLine("Tiếng chm kêu: ");
                chim.speak();
                Console.WriteLine("Di chuyển chim: ");
                chim.move();
                Console.WriteLine("chim ăn: ");
                chim.eat();
                break;

            default:
                Console.WriteLine(" nhap khong hop le");
                break;
            }
        }
Пример #2
0
        public static void Main(String[] args)
        {
            Animal a = new Animal(5);
            Dog    d = new Dog();
            Cat    c = new Cat();

            d.ruff();
            Console.WriteLine(d.age());
            c.meow();
            Console.WriteLine(c.age());
            a.eat();
            d.eat();
            c.eat();
            d.run();
            c.prance();
        }