|
public class aa { public bool ss {。。。} } 和 public class aa { public static bool ss {。。。} } 在使用和功能方面有何差别? 调用该类,没有用static时要实例化,才能调用该类的方法,用料static就可以直接调用,两者有何区别,那种根好? |
|
|
|
很简单, 有static时, 没有实例化类也可以用它.也就是说
aa a;时就会编译ss. 如果没有, 就要到 aa a = new aa();时才会编译. |
|
|
每实例化一次就要分配内存,静态不需要。
|
|
|
用静态的好拉。省内存。不过现在内存不值钱了。哈哈
|
|
|
static不用实例化,首选它.
|
|
|
static不用实例化,首选它.
到处都是 只有static 的 helper类 这样的程序和c语言写出来有什么区别? |
|
|
对于只需存储一次,创建一个单独副本的用static.但是加了static,就必须通过类访问这个变量,而不能通过类的实例来访问.
|
|
|
static成员不能访问非static成员
|
|