如下的程序:
public class TestStaticClass { public static void main(String[] argv)
{
System.out.println(new TestStaticInner().a);
}
static class TestStaticInner
{
private int a;
}
}
可以编译通过。
那么把类声明为静态类有何用?
public class TestStaticClass { public static void main(String[] argv)
{
System.out.println(new TestStaticInner().a);
}
static class TestStaticInner
{
private int a;
}
}
可以编译通过。
那么把类声明为静态类有何用?
静态类以后就不用new了啊!呵呵!
System.out.println(new TestStaticInner().a);
A.test();
} static class TestStaticInner {
private int a;
} class TestStaticInner2 {
private int a;
}
}class A {
public static void test() {
new TestStaticClass.TestStaticInner();
new TestStaticClass().new TestStaticInner2();
}
}如上面的 代码
static 是相对 这个类外 的,有static 就不需要new 对象了
用new在内存中不一样