aspose file tools*
The moose likes Java in General and the fly likes static block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
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: 40052
    
  28
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://aspose.com/file-tools
 
subject: static block