【发布时间】:2015-06-11 10:20:45
【问题描述】:
你能告诉我以下两个类有什么区别
public static class Product
{
public static int AddData(int x, int y)
{
return x + y;
}
}
public class Product
{
public static int AddData(int x, int y)
{
return x + y;
}
}
因为我们可以在两个类中以相同的方式访问 AddData 方法。
【问题讨论】:
-
你不能实例化第一类。所以如果你想向这个类添加另一个方法,它必须是静态的。第二类可以被实例化,所以你也可以给它添加非静态方法(这只是我想到的一点)。