| Author |
static block
|
Urs Waefler
Ranch Hand
Joined: Mar 13, 2007
Posts: 77
|
|
Hi This is my code: class B { static { B x = new B (); } public static void main (String [] args) { } } I do not properly understand static block. Could anybody give me some hints. What is it? Regards Urs
|
SCJP 1.4
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
If I understand your question correctly, what you have is called a static initialiser. There is discussion on the Ranch in several places, this, and this, which is maybe less helpful, being two recent examples I found with a search.
|
 |
suji kumar
Greenhorn
Joined: Nov 08, 2006
Posts: 10
|
|
|
static block will be executed when the class gets loaded...
|
 |
Murad Iqbal
Ranch Hand
Joined: Dec 09, 2003
Posts: 90
|
|
|
Yup, the code in a static initializer block is executed by the virtual machine when the class is loaded.
|
 |
 |
|
|
subject: static block
|
|
|