java使用。主函数中的jar文件
一旦我进口。将jar文件添加到主函数。我每件事都做对了 单击项目-‐gt;房地产-;JavaBuildPath-;图书馆-;AddJARs)
现在,如果我想开始使用中的类中的方法和变量。jar文件
在main函数中,我是否只声明类类型的对象并开始使用类中的方法
我试过了,它一直给我error: "Syntax error on token ";", @ expected"
package abcd;
import util.Car;
public class Showroom {
Car firstCar = new Car("BMW"); //overloaded constructor
Car secondCar = new Car(); //default constructor is empty
secondCar.setName("Lexus"); //setName is a method in the Car class but I get the above error for using this.
}
我知道它有一个非常简单的解决方案,但你能解释一下是什么和为什么吗
# 1 楼答案
您需要在可执行块(构造函数、方法、初始化器块)中编写语句
# 2 楼答案
在java中,只能在某些方法或块中编写逻辑
像这样的