What are advantages and usage of static block?

Questions by naggeek

Showing Answers 1 - 12 of 12 Answers

Amit Patil

  • Sep 17th, 2007
 

Static block is executed the first time the class is loaded in JVM where as static methods are executed only when they are called.Hence static block can be used to perform key operations which could be required when the class is loaded.

sampra

  • Feb 14th, 2008
 

Static block excution is done at class loading tim there is no need of object creation so we can save some memory in heap.

  Was this answer useful?  Yes

static block is executed whenever a class is loaded by the JVM.....
hence in case you want certain code to executed or say some objects of a class avaliable to ur application as soon as the application starts you can put in the relevant code there....

vinny

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions