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 8 primitive data types in java?
Can I override protected method in java?
How do you get length in java?
Implement two stacks using a single array.
What is the purpose of object oriented programming?
How does map works in java?
Write a program to find the whether a number is an Armstrong number or not?
What is hotjava?
How many bits is size_t?
Do I need to import java.lang package any time? Why?
Which data type is class in java?
Can you run java program without main method?
If you do not want your class to be inherited by any other class. What would you do?
What is java objectoutputstream?
Can a class be defined inside an interface?