• 抽象类与抽象方法


    抽象类为基类:

    abstract class  Animal     {         string name;

            public string Name         {             get { return name; }             set { name = value; }         }         char gender;

            public char Gender         {             get { return gender; }             set { gender = value; }         }         int age;

            public int Age         {             get { return age; }             set { age = value; }         }         public Animal(string name, char gender, int age)         {             this.name = name;             this.gender = gender;             this.age = age;         }         public   abstract  void Shout();

        

    派生类(子类):

      class Cat:Animal
        {
            public Cat(string name, char gender, int age)
                : base(name, gender, age)
            {        
            }
            public   override void Shout()
            {
               Console . WriteLine("喵喵叫!");
            }

      class Dog:Animal
        {
            public Dog(string name, char gender, int age)
                : base(name, gender, age)
            {
            }
            public    override  void Shout()
            {
                Console.WriteLine("汪汪叫!");
            }
        }

    主方法:

     class Program     {         static void Main(string[] args)         {             Cat cat=new Cat ("加菲猫",'公',3);             cat.Shout();             Dog dog = new Dog("旺财", '母', 5);             dog.Shout();             Console.ReadKey();

            }     }

  • 相关阅读:
    MybatisPlus自动填充公共字段的策略
    docker内的应用访问宿主机上的mysql和Redis
    Spingboot整合Redis,用注解(@Cacheable、@CacheEvict、@CachePut、@Caching)管理缓存
    集群中的session共享问题解决方案
    Java并发之原子性,有序性,可见性,以及Happen-Before原则
    Java NIO技术概述
    Java反射机制总结
    java线程以及定时任务
    java流概述以及文件读写示例
    CSS常用内容总结(二)
  • 原文地址:https://www.cnblogs.com/hnzsb-vv1130/p/3849291.html
Copyright © 2020-2023  润新知