aspose file tools
The moose likes Java in General and the fly likes static block Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "static block" Watch "static block" New topic
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
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: static block
 
Similar Threads
a question about static clause
Simple code
When to use Static initial block?
code called before constructor
Constructor usage in superclasses