using System;
using System.Collections.Generic;
using System.Text;namespace ChooseSubject
{
public class Car
{
private int weight;
private int speed;
public Car(int Weight, int Speed)
{
weight = Weight;
speed = Speed;
}
public void setweight(int Weight)
{
weight = Weight;
}
public void setspeed(int Speed)
{
speed = Speed;
}
public int getspeed()
{
return speed;
}
public int getweight()
{
return weight;
}
}
public class Sportcar : Car
{
private string color;
//public Sportcar(int Weight, int Speed, string Color): base(Weight, Speed)
//{
// setweight(Weight);
// setspeed(Speed);
// color = Color;
//}
public Sportcar(int Weight, int Speed, string Color)
{
setweight(Weight);
setspeed(Speed);
color = Color;
}
public void setcolor(string Color)
{
color = Color;
}
public string getcolor()
{
return color;
}
public static void Main()
{
Car car = new Car(100, 100);
Sportcar sportcar = new Sportcar(100, 200, "blcak");
Console.WriteLine("car's weight is " + car.getweight());
Console.WriteLine("car's speed is " + car.getspeed());
Console.WriteLine("sportcar's weight is " + sportcar.getweight());
Console.WriteLine("sportcar's speed is " + sportcar.getspeed());
Console.WriteLine("sportcar's speed is " + sportcar.getcolor());
}
}
}
提示的错误是:错误 1 “Car”方法没有采用“0”个参数的重载 J:\demo\test1\ChooseSubject\ChooseSubject\Program.cs 44 16 ChooseSubject是这里出的错。“public Sportcar(int Weight, int Speed, string Color)”
一定要这样才行。public Sportcar(int Weight, int Speed, string Color):base(int Weight,int Speed)
为什么要这样?烦请详细解释下,小弟正在自学。
解决方案 »
- C#一个方法里代码同时运行(不用线程)
- 如何将输出的混合数据流分离开来
- WinForm程序,客户端如何从服务器下载文件?
- ASPxGridView控件如何像GridView里的rowdatabound事件一样重新绑定
- 自定义控件属性显示的问题
- 求个C#+SVERVER 2000的小型网站!!!新手,为了工作模仿做个网站!!!请有的给下!!100分
- C# TreeView控件问题
- 在打开一解决方案时,出现错误提示,如何修改呢?
- C# FTP问题
- 还痛苦,再发张帖子发泄,发泄。(~~小程序员的悲剧人生``~~)请BS我,不要AW我~
- 请教各位大锅,关于 ITypeProvider 的实现问题【C#、RuleSetDialog、ITypeProvider 】
- 【求教,急!!!! 安装 部署 如何定制真正的自定义对话框?????? 】
一定要这样才行。public Sportcar(int Weight, int Speed, string Color):base(int Weight,int Speed)
========================================================================
这个错误只是说明 Car类 没有 名为Car不带参数的构造方法而已;并不是一定改成你说的这种情况;但你改的也是可以的.
你的做法是指定创建派生类实例时应调用的基类构造函数;
{
public Car(){}
}
这样就不用去调他的父类了
这样就不用去调他的父类了
也可在下面用 override 重写如 public override Car(){int Weight, int Speed)}
再就是base了