zoukankan      html  css  js  c++  java
  • 抽象类与抽象方法

    抽象类为基类:

    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();

            }     }

  • 相关阅读:
    04: vue生命周期和实例属性和方法
    03: vuejs 事件、模板、过滤器
    (打补丁 )patch
    zabbix安装
    zabbix简介
    linux 虚拟网络模型介绍
    虚拟化
    虚拟化分类(半虚拟化和全虚拟化)
    playbook详解—YAML格式的文本
    ansible的介绍和一些基本模块介绍
  • 原文地址:https://www.cnblogs.com/hnzsb-vv1130/p/3849291.html
Copyright © 2011-2022 走看看