class inside static method
poguy
Member Posts: 91 ■■□□□□□□□□
public class Test {
public static void main(String args[]) {
class Foo {
public int i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println(“i = “ + foo.i);
}
}
So Foo is a static class, how come it can init an instance from static class?
thank you
public static void main(String args[]) {
class Foo {
public int i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println(“i = “ + foo.i);
}
}
So Foo is a static class, how come it can init an instance from static class?
thank you
Comments
-
JDMurray Admin Posts: 13,090 AdminThat code won't compile with Java 1.6. Try this instead:
class Test { [B][I]static [/I]class Foo { public int i = 3; }[/B] public static void main(String args[]) { Object o = (Object)new Foo(); Foo foo = (Foo)o; System.out.println("i = " + foo.i); } }
As I understand it, instantiating static classes is legal and allowed in Java, but apparently there is no performance or access advantage in doing it.