C#认证二单元 第一题
2021-05-13 20:27
标签:rtu logs virt 认证 task http using write img 1:运行结果 代码如下: using System; namespace Txst2_1 C#认证二单元 第一题 标签:rtu logs virt 认证 task http using write img 原文地址:http://www.cnblogs.com/HCBC/p/7536021.html
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
{
class Animal
{
private Boolean m_sex;
private int m_age;
public bool Sex
{
get { return m_sex; }
set { m_sex = false; }
}
public int Age
{
get { return m_age; }
set { m_age = value; }
}
public virtual string Introduce()
{
if (Sex == true)
return "This is a male Animal";
else
return "This is a female Animal";
}
}
class Dog:Animal
{
public Dog()
{
Sex = true;
}
public override string Introduce()
{
if (Sex == true)
return "This is a male Dog";
else
return "This is a female Dog";
}
}
class Cat:Animal
{
public override string Introduce()
{
if (Sex == true)
return "This is a male Cat";
else
return "This is a female Cat";
}
}
class Program
{
static void Main(string[] args)
{
Animal ani = new Animal();
Console.WriteLine(ani.Introduce());
Animal dog = new Dog();
Console.WriteLine(dog.Introduce());
Animal cat = new Cat();
Console.WriteLine(cat.Introduce());
Console.Read();
}
}
}