|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
来吧!老师们!我代表千千万万的asp.net/C#的初学者在这里呼唤着!usingSystem;
namespacedirtysalt
{
publicclassCar//classofcar,hasattributeofweightandspeed
{
privateintweight;
privateintspeed;
publicCar(intWeight,intSpeed)
{
weight=Weight;
speed=Speed;
}
publicvoidsetweight(intWeight)
{
weight=Weight;
}
publicvoidsetspeed(intSpeed)
{
speed=Speed;
}
publicintgetspeed()
{
returnspeed;
}
publicintgetweight()
{
returnweight;
}
};
publicclassSportcar:Car//inheritclassofCar,hasattributesofweight,speed,color
{
privatestringcolor;
publicSportcar(intWeight,intSpeed,stringColor):base(Weight,Speed)
{
setweight(Weight);
setspeed(Speed);
color=Color;
}
publicvoidsetcolor(stringColor)
{
color=Color;
}
publicstringgetcolor()
{
returncolor;
}
publicstaticvoidMain()
{
Carcar=newCar(100,100);
Sportcarsportcar=newSportcar(100,200,"blcak");//herehasaproblem
Console.WriteLine("carsweightis"+car.getweight());
Console.WriteLine("carsspeedis"+car.getspeed());
Console.WriteLine("sportcarsweightis"+sportcar.getweight());
Console.WriteLine("sportcarsspeedis"+sportcar.getspeed());
Console.WriteLine("sportcarsspeedis"+sportcar.getcolor());
}
}
}
另外,小型软件代码重用价值低,没有必要跨平台;大型软件,有严格的规划、部署,不可以随意跨平台。 |
|