Friday 15 March 2013

java - Initializer blocks -


Do System.out.println () statements always execute? Let me say I have

  square c2 {{System.out.println ("initializer"); } Public static zero main (string A []) {System.out.println ("main"); C2 OB1 = new C2 (); }}   

Then why the "initiator" statement will also be printed. Is this a constructor statement?

Yes, it will print:

  main initiator   

When you call the constructor of c2 then your initializer will be called. Your default constructor looks for the class c2 such as:

  c2 () {{System.out.println ("initiator"); }} See the JLS for   

.

No comments:

Post a Comment