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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

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

Post by devlam »

I don't get the last statement:
T is a top-level class, and an assert statement lexically nested within T is executed.

Is it possible to show a small clean example of that situation?

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

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

Post by admin »

Code: Select all

public class SomeClass{
 
 static int j = 5;
 static{
   assert j == 5:"invalid"; //j will be 5 because the class will have been initialized before this statement is executed.
 }

}
Basically, what it means is that a class or interface will be initialized before any assert statement that exists within the class is executed.

HTH,
Paul.

devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

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

Post by devlam »

The problem with the understanding I have is that if an assert statement is executed you are in the class so it's evidently the class is initialized.
In the example you give some of the other reasons for initializing must have happened before the static block will be "executed". What is wrong with my understanding?

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

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

Post by admin »

Sorry, I am not really sure. You might want to consult JLS for further details.

-Paul.

cosmindumy
Posts: 7
Joined: Sun Apr 13, 2014 4:04 pm
Contact:

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

Post by cosmindumy »

Explanation is right, but the correct answer is "super two" 3rd option, not 4th.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests