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

    }
    }
    }

  • 相关阅读:
    (考研)散列表和hashcode和hashmap
    java基本数据类型和引用类型
    Java 中的语法糖(7/15整个周六上午总结)
    数据库第一天-数据库索引
    MonoBehaviour生命周期
    Unity基础知识
    SQLite3笔记
    cocos_js写文件
    UGUI_屏幕适配
    KMS算法
  • 原文地址:https://www.cnblogs.com/YuJiaJia/p/7506953.html
Copyright © 2011-2022 走看看