| Author |
what is the difference between static variable and static block
|
Anand Sivathanu
Ranch Hand
Joined: Jun 25, 2010
Posts: 76
|
|
|
what is the difference between static variable and static block in java
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
What's the difference between a variable and a constructor?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
Or more generally, ask yourself, "What is a 'block' of code? And what would happen if I put a 'static' modifier in front of it?"
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Anand Sivathanu
Ranch Hand
Joined: Jun 25, 2010
Posts: 76
|
|
if i put static for a block of code,then it will be loaded once when is class is loaded by jvm.
static variable is class variable,which will be loaded when the class is loaded.
i donot know the exact difference between these to two?
can you explain?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
Anand Sivathanu wrote:
i donot know the exact difference between these to two?
can you explain?
You mean to say, the order which the load?
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Anand Sivathanu wrote:if i put static for a block of code,then it will be loaded once when is class is loaded by jvm...
The block will do more than just load. When a class is loaded, a static block of code will execute.
Look at this code and try to predict the output. Then test it by compiling and running.
|
 |
 |
|
|
subject: what is the difference between static variable and static block
|
|
|