This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes can we have multiple static blocks? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we have multiple static blocks?" Watch "can we have multiple static blocks?" New topic
Author

can we have multiple static blocks?

rakesh repala
Greenhorn

Joined: May 23, 2008
Posts: 5
can we have multiple static blocks in one class?how it will be exceution statrs?


rakesh
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi rakesh,

welcome to the ranch

You can have multiple static initializer blocks in Java and they are executed in the order they appear in your source code.

Marco
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
Welcome to the ranch

In short, yes there can be multiple static blocks, and they are executed from top to bottom as they appear in the code.
This article seems to give a nice explanation on static blocks.
rakesh repala
Greenhorn

Joined: May 23, 2008
Posts: 5
thanks...
Jitendra Jha
Ranch Hand

Joined: Jan 28, 2007
Posts: 91
rakesh

Here at the javaranch we try to learn not teach
if only you had put multiple static blocks in your code and checked the result,you would not have had this doubt..
we feel the best way to learn is to do a lot of coding.Please feel free to ask and share your knowledge
Happy ranching


Jitendra
SCJP1.5
SCWCD1.5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Originally posted by Jitendra Jha:
we feel the best way to learn is to do a lot of coding.

I agree. Whenever you want to ask "will this compile" or "is this possible", the best thing to do is simply test it out. The compiler and JVM have better knowledge of Java than any of us do.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we have multiple static blocks?
 
Similar Threads
What is the main Use Static block ?
What is the main Use Static block ?
Could Class be synchronized ?
Bizarre static member
Interfaces