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?
About Question com.enthuware.ets.scjp.v6.2.629 :
Moderator: admin
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.629 :
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.
}
}
HTH,
Paul.
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.629 :
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?
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?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.629 :
Sorry, I am not really sure. You might want to consult JLS for further details.
-Paul.
-Paul.
-
- Posts: 7
- Joined: Sun Apr 13, 2014 4:04 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.629 :
Explanation is right, but the correct answer is "super two" 3rd option, not 4th.
Who is online
Users browsing this forum: Bing [Bot] and 9 guests