-4

please state the advantages of use of static blocks in java. Why we need static blocks in our program.

Dis_Pro
  • 633
  • 1
  • 10
  • 21
  • 1
    Possible duplicate of [What is the difference between a static variable and a dynamic variable in java/oops?](http://stackoverflow.com/questions/2198693/what-is-the-difference-between-a-static-variable-and-a-dynamic-variable-in-java) – Vinay Prajapati Jan 28 '16 at 04:46
  • Possible duplicate of [What does the 'static' keyword do in a class?](http://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-a-class) –  Jan 28 '16 at 04:53

1 Answers1

1

Java Static Variables: Java instance variables are given separate memory for storage. If there is a need for a variable to be common to all the objects of a single java class, then the static modifier should be used in the variable declaration.

Java Static Methods: Static methods should be invoked with using the class name though it can be invoked using an object. ClassName.methodName(arguments) or objectName.methodName(arguments)

Java Static Classes: For java classes, only an inner class can be declared using the static modifier. For java a static inner class it does not mean that, all their members are static. These are called nested static classes in java.

Rahul Ahirrao
  • 319
  • 3
  • 10