zoukankan      html  css  js  c++  java
  • test2-1

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace test2_11
    {
    class Animal//基类
    {
    private bool m_sex;
    private int m_age;
    public Animal()
    {
    m_sex = false;
    }
    public bool Sex
    {
    get { return m_sex; }
    set { m_sex = value; }
    }

    public int Age
    {
    get { return m_age; }
    set { m_age=value; }
    }
    public virtual void Introduce()//虚方法
    {
    if (Sex == true)
    Console.WriteLine("this is a male Animal");
    if (Sex == false)
    Console.WriteLine("this is a female Animal");
    }
    }
    class Dog:Animal
    {
    public Dog()
    {
    Sex = true;
    }
    public override void Introduce()
    {
    if (Sex == true)
    Console.WriteLine("this is a male Dog");
    if (Sex == false)
    Console.WriteLine("this is a female Dog");
    }

    }
    class Cat:Animal
    {
    public override void Introduce()
    {
    if (Sex == true)
    Console.WriteLine("this is a male Cat");
    if (Sex == false)
    Console.WriteLine("this is a female Cat");
    }
    }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace test2_11
    {
    class Program
    {
    static void Main(string[] args)
    {
    Animal ani = new Animal();
    Dog dog = new Dog();
    Cat cat = new Cat();
    ani.Introduce();
    dog.Introduce();
    cat.Introduce();

    }
    }
    }

  • 相关阅读:
    二维数组排序
    正则验证
    yii2视频教材
    yii2数据库简单操作
    MySQL(zip版)安装教程
    OpenCV插件
    机器视觉项目总结——光源
    VS2017运行YOLOv4
    VS打开cmd(直接在项目路径)
    【转载】Win10安装Ubuntu子系统
  • 原文地址:https://www.cnblogs.com/YuJiaJia/p/7506953.html
Copyright © 2011-2022 走看看