我有一门课叫做货币
public class Monetary
{
double value;
String type;
public Monetary()
{
value = 0;
type = "";
}
public double getValue()
{
return value;
}
public void setValue(double x)
{
x = this.value;
}
我正在测试 get 和 set 方法,所以我制作了一个测试类,如下所示
public class test
{
public static void main(String [] args)
{
double test = 5000;
Monetary testM = new Monetary();
testM.setValue(5000);
System.out.println(testM.getValue());
}
}
问题是java打印的结果不是5000.0,而是0。我不明白为什么会这样。这些方法不正确吗?