码迷,mamicode.com
首页 > 其他好文 > 详细

第二节

时间:2017-09-17 23:29:20      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:main   oid   val   override   rtu   namespace   threading   als   gen   

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

namespace Txst2_1
{
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();
}
}
}

第二节

标签:main   oid   val   override   rtu   namespace   threading   als   gen   

原文地址:http://www.cnblogs.com/zjk123/p/7538411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!