Answer Posted / ranganathkini
A static block or a static initializer is a block that
appears within a class definition but outside any member
definition with the keyword static ahead of it. Example:
class MyClass {
private static double myValue;
static {
myValue = Double.parseDouble( System.getProperty(
"version" ) );
}
}
It is mainly used to perform static construction i.e.
initialization of static variables (see above example). The
static initializer is executed when the class is loaded by
the JVM.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What are the differences between this and super keyword?
What's the access scope of protected access specifier?
What is the benefit of lambda expressions?
Difference between operator overloading and function overloading
How to write custom exception in java?
What is private protected in java?
What is hasnext in java?
Does garbage collection occur in permanent generation space in jvm?
Which package is always imported by default?
How does arraylist work in java?
What are design patterns and please explain?
Where to store local variables?
What is a priority queue java?
Under what conditions is an object’s finalize() method invoked by the garbage collector?
Is break statement can be used as labels in java?