类的继承实例讲解
类的继承实例讲解
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 类的继承
{
public class Program
{
public static void Main(string[] args)
{
人 ren = new 人();
ren.物种 = "高等生物";
ren.脚的数量 = 2;
ren.Eat();
ren.Name = "张三";
ren.Age = 15;
Console.WriteLine("我叫{0},我今年{1}岁了,我是{2},我有{3}脚,我除了有生物的{4}以外我还会{5}", ren.Name, ren.Age, ren.物种, ren.脚的数量, ren.Eat(), ren.Say());
Console.ReadKey();
}
}
public class 生物
{
public string 物种;
public int 脚的数量;
public string Eat()
{
return "吃东西";
}
}
public class 人 : 生物
{
public string Name;
public int Age;
public string Say()
{
return "说话";
}
}
}
文章来源:www.900544.com
浙公网安备 33010602011771号