using System;
namespace dirtysalt{
public
class Car//class of car,has attribute of 'weight' and 'speed'
{
proected int weight;
proected int speed;
proected string color
public Car(int Weight,int Speed,string Color){
weight=Weight;
speed=Speed;
color = Color;
}
public
int
Weight{
get{return weight;}
set{weight = value;}
}
public
int
Speed{
get{return speed;}
set{speed = value;}
}
public string Color{
get{return color;}
set{color = value;}
}
}
public class Sportcar:Car//inherit class of Car,has
attributes of 'weight','speed','color'
{
public
Sportcar(int Weight,int Speed,string Color):base(Weight,Speed,Color)
{
}
}
public static void Main()
{
Sportcar sportcar=new Sportcar(100,200,"blcak");//here has a problem
Console.WriteLine("sportcar's weight is "+sportcar.Weight);
Console.WriteLine("sportcar's speed is "+sportcar.Speed);
Console.WriteLine("sportcar's speed is "+sportcar.Color);
}
}
}
注:不存在没有颜色的车吧,所以把颜色放入父类不是很好吗?而且,重量,颜色可以看作是车的属性啊。 你觉得呢。