【问题标题】:Undefined constructor instance未定义的构造函数实例
【发布时间】:2022-11-04 23:40:18
【问题描述】:

我有两个班级:人群和客户。我在来自客户类的人群类中创建了一个构造函数实例。但是,我收到一个错误。

这是客户构造函数:

customer(int id, Clock clock, Worker[] worker, Table table, int ORDER){
    setName("Customer" + id);
    this.clock = clock;
    this.worker = worker;
    this.table = table;
    this.ORDER= ORDER;
};

这是 crowd 类中的构造函数实例:

customer customer = new customer(clock, worker, table, drinkRatio());

【问题讨论】:

  • 假设所有变量都已定义,您似乎正在使用第一个参数:一个 int id;无论如何,您应该提供错误消息。并且不需要构造函数末尾的分号。但是,我建议您使用标准的 java 编码约定(例如,类名是“Customer”,大写 C)。
  • 前几天你不是问a very similar question吗?这次您没有传递id 参数。在问这里之前,您能否更彻底地检查您的代码?

标签: java constructor


【解决方案1】:

你没有传入 id,5 个参数,但只有 4 个传入

【讨论】:

    猜你喜欢
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多