About Question com.enthuware.ets.scjp.v6.2.293 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.293 :

Post by ETS User »

Although the answer remains the same the class is actually first referenced when executing the class file with the java command so if the code was changed to :

Code: Select all

public class StaticTest
{
   static
   {
      System.out.println("In static");
   }
   {
      System.out.println("In non - static");
   }
   public static void main(String args[ ])
   {
       System.out.println(" 1 ");
       StaticTest st1 = new StaticTest();            //2
       System.out.println(" 2 ");
       StaticTest st2 = new StaticTest(); //3
   }
}
You would get the same answer. Line //1 does not actually cause the static init blocks to run as they were already run in order to execute the main method is called.

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.293 :

Post by admin »

You are right. Explanation is updated to reflect this fact.

Thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests