调用setPrice方法初始化price成员变量
调用setPrice方法初始化price成员变量
调用setPrice方法初始化price成员变量哪一步出错了
参考下面代码
public class A {
public static void main(String[] args) {
Price price = new Price(200, "zhangsan", 10); //初始化
System.out.println(price.toString()); //调用toString()方法
}
}
class Price {
private double price;
private String name;
private long id;
static String static_name = "这是静态变量";
//静态代码块
static {
System.out.println(static_name);
}
//构造方法
public Price(double price, String name, long id) {
this.price = price;
this.name = name;
this.id = id;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public String toString() {
return "Price [price=" + price + ", name=" + name + ", id=" + id + "]";
}
}