StaticIniDemopublic class StaticIniDemo extends Object Show static initializers. These are run when the class is loaded.
If you run the main program here, you will see the static
initializer before the "About to load class", since the class
is loaded before main gets run. If you copy the guts of main into
another class, the messages will come out in the "expected" order. |
Constructors Summary |
---|
public StaticIniDemo()A constructor -- called when object is instantiated.
System.out.println("In static initializer");
System.out.println("In Constructor");
|
Methods Summary |
---|
public static void | main(java.lang.String[] a)
try {
System.err.println("About to load class");
Class c = Class.forName("StaticIniDemo");
System.err.println("About to construct instance");
Object sd = c.newInstance();
System.err.println("Object is " + sd);
} catch (Exception e) {
e.printStackTrace();
}
|
|