zoukankan      html  css  js  c++  java
  • 0104-抽象方法和多态

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace _04抽象方法和多态
    {
        class Program
        {
            static void Main(string[] args)
            {
                Animal[] an = {new Cat(), new Dog(),};
                for (int i = 0; i < an.Length; i++)
                {
                    an[i].Bark();
                    an[i].Eat();
                }
                Console.ReadKey();
            }
        }
        //抽象成员只能存在于抽象类中
        abstract class Animal
        {
            public abstract void Bark(); //父类没有办法确定子类如何实现
    
            public void Eat()
            {
                Console.WriteLine("动物舔着吃");
            }
    
        }
        //子类必须使用override关键字实现父类所有抽象方法
        class Cat : Animal
        {
            public override void Bark()
            {
                Console.WriteLine("猫咪喵喵的叫");
            }
        }
        class Dog : Animal
        {
            public override void Bark()
            {
                Console.WriteLine("狗狗旺旺的叫");
            }
        }
    }
    凡哥,别他妈吹牛逼了
  • 相关阅读:
    进程与线程的区别
    开启线程的两种方式
    线程
    生产者消费者模型(重要)
    队列
    互斥锁
    守护进程(了解)
    Process对象的其它方法与属性(join)
    僵尸进程与孤儿进程
    Servlet
  • 原文地址:https://www.cnblogs.com/sdlz/p/14690515.html
Copyright © 2011-2022 走看看