将题主的代码写了一点,题主可以作为参考,望采纳
public class Clock {
//你的参数
String structure;
String style;
double price;
String time;
//无参构造
public Clock() {
}
//全参构造
public Clock(String structure, String style, double price, String time) {
this.structure = structure;
this.style = style;
this.price = price;
this.time = time;
}
//以下为全部参数的get和set方法
public String getStructure() {
return structure;
}
public void setStructure(String structure) {
this.structure = structure;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public static void main(String[] args) {
//创建对象
Clock clock=new Clock();
// 没有给structure设置值 打印为空
System.out.println(clock.structure);
// 给structure设置值,打印“我是structure”
clock.setStructure("我是structure");
System.out.println(clock.structure);
}
public void clock改为public Clock,然后标红的那一行给3个参数,两个String一个double
你是不是没写有参构造
估计你是想那个哥public void clock方法作为构造函数吧,应该把void删除,并且把clock改为Clock