继承 以 c# 为例
public class Fruit
{
string color;
public Fruit(string color)
{
this.color=color;
}
public string Color
{
get
{ return this.color }
set
{this.color=value;}
}
}//Fruit 类结束
public class Apple:Fruit
{
string name;
public Apple(string color,string name):base(color)
{
this.name=name;
}
public string Name//扩展属性
{
get {
return this.name;
}
set
{
this.name=value;
}
}
}
public class test
{
public static void Main()
{
Apple myapple=new apple("red","apple");
Console.WriteLine(myapple.Color);//基类属性
Console.WriteLine(myapple.Name);//扩展属性
Console.ReadKey();
}
}