用base怎么调用抽象类的构造函数啊?

dbms_output 2004-09-04 05:33:09
using System;

abstract public class Employee
{
public string name;
public char sex;

public Employee(string na,char se)
{
name=na;
sex=se;
}

abstract public void display();
}
class Officer:Employee
{
char empClass;
int experience;
bool vehicle;
static string na;
static char se;

public Officer(char em,int ex,bool veh):base(string na,char se)
{
empClass=em;
experience=ex;
vehicle=veh;
}
public override void display()
{
Console.WriteLine("姓名"+name);
}
}

class AbstractDemo
{
static void Main()
{
Officer.na="linwenshan";
Officer.se='t';
Officer w=new Officer('m',100,true);
}
}

象这样如果都有参数不知道该怎么办?
...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxqqk 2004-09-04
  • 打赏
  • 举报
回复
如forever_chang所言
Firestone2003 2004-09-04
  • 打赏
  • 举报
回复
是的
forever_chang 2004-09-04
  • 打赏
  • 举报
回复
是不是应该这样啊
public Officer(string na,char se,char em,int ex,bool veh):base(na,se)
{
empClass=em;
experience=ex;
vehicle=veh;
},
dbms_output 2004-09-04
  • 打赏
  • 举报
回复
那base()里面两个参数在officer实例化的时候怎么传递给这两个参数呢?
triout 2004-09-04
  • 打赏
  • 举报
回复
代码:

public Officer(char em,int ex,bool veh):base(string na,char se)
{
empClass=em;
experience=ex;
vehicle=veh;
}

并没有什么错误,在调用基类的构造函数上是正确的。但你的错误是:怎么能这么写?

应该写为:

public Officer(char em,int ex,bool veh):base(na,se)
{
empClass=em;
experience=ex;
vehicle=veh;
}


注意,在调用函数的时候,不能定义变量,直接把变量传递就可以了。

另外,你在调用base的时候,你的na和se从哪里来的?
shuhill 2004-09-04
  • 打赏
  • 举报
回复
帮顶

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧