what is a static block?

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


Please Help Members By Posting Answers For Below Questions

Explain working of call by reference function invoking.

594


What are recursive functions? Give some examples?

620


What is a newline character in java?

566


what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????

1806


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

583






Why is boolean important?

593


What language is pass by reference?

574


What is meant by design patterns?

588


What are keywords in java?

581


Why is java architectural neutral?

617


Can a constructor call the constructor of parent class?

541


Why do we use regex?

563


Can you use abstract and final both with a method?

573


String and stringbuffer both represent string objects. Can we compare string and stringbuffer in java?

557


What languages are pass by reference?

543