gpt4 book ai didi

java - 为什么此导入不能在 Eclipse 中跨包工作?

转载 作者:行者123 更新时间:2023-12-01 18:01:42 24 4
gpt4 key购买 nike

这是项目架构: enter image description here

这是无法编译的 Car 类:

package car;

import engine.Engine;

public class Car {
private Engine engine;

/***
* Constructor
* @param engine The engine that the car object will have
*/
Car(Engine engine) {
engine = new Engine(engine); // Use the Engine copy constructor
}
}

错误如下: enter image description here

这是引擎包中的Engine类:

package engine;

public class Engine {
private String name;
private int displacement;

public Engine(String name, int displacement) throws Exception {
setName(name);
setDisplacement(displacement);
}
public String getName() {return name;}
public int getDisplacement() {return displacement;}

private void setName(String name) throws Exception {
if (name.trim().length() == 0) {
throw new Exception("Engine name cannot be blank");
}
}
private void setDisplacement(int displacement) throws Exception {
if (displacement < 0) {
throw new Exception("Engine displacement cannot be zero or negative");
}
}
}

最佳答案

尝试清理 Project --> clean 中的项目

关于java - 为什么此导入不能在 Eclipse 中跨包工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60617972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com