public class MyObject { MyObject(){ System.out.println("MyObject is created!"); }
public static void main(String[] args){ MyObject[] myObjects =new MyObject[5]; // nothing printed in thing line. System.out.println("By now, nothing has been printed. myObjects have not been created!"); myObjects[0]=new MyObject(); //involve MyObject's Constructor. } }
public class TestThread extends Thread { private int count=5; private static int threadCount=0; public String toString(){ return super.getName()+" " + (count--); } public TestThread(){ super("#Thread" + (++threadCount)); start(); } public void run(){ while(true){ System.out.println(this); if (count==0) return; } } }