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

    }
    }
    }

  • 相关阅读:
    nopCommerce中缓存学习
    EF
    路由
    webapi的加密方式
    生成N位数字随机数
    C# DataTable 转 实体类
    WebBrowser 打印
    文件上传控件,格式统一
    sqlserver 表循环-游标、表变量、临时表
    VB 老旧版本维护系列---迷之集合- dataTable
  • 原文地址:https://www.cnblogs.com/YuJiaJia/p/7506953.html
Copyright © 2011-2022 走看看