<分区>
我有两个不同的程序,一个使用 int
,另一个使用 Double
。
对于下面的代码,我得到了 NullpointerException
public class Solution {
Double cost;
void addTax(Double b)
{
cost+=b;
}
public static void main(String[] args)
{
new Solution().addTax(30.00);
}
}
但对于以下使用 int 的代码,不会出现任何运行时错误。
public class Solution {
int cost;
void addTax(int b)
{
cost+=b;
}
public static void main(String[] args)
{
new Solution().addTax(30);
}
}
那怎么可能呢?请解释一下。