: Java Compilation error.
2 Answer(s)      8 years ago
Posted in : Java Beginners


View Answers

November 1, 2008 at 10:06 AM

Hi friend,

Static block will execute when ever execution starts, it
means this block executes first of all, where as static
block have to call seperately and also it can call with out
object instance.

Static Block is executed when the Program starts.

Example :

public class StaticExample {


public static void main(String args[]){


When we run this program it will print Hello.

Static Methods are executed when those methods are called
from another static class or method

Example :

public class StaticExample {

static void printString(){

static void testStaticMethod(){

public static void main(String args[]){

static block is used to initialize the variables during the
JVM startup.
static methods are getting called with out creation of any

A STATIC block is automatically executed the first time the class where it is defined is called.
A Static Method is excuted only when a static call is made to this method.

For more information on java visit to :



November 1, 2008 at 1:46 PM

static block is automatically executed when the program executes. And a static method u can directly call within the same class. In other class u can call using classname.method() without creating an instance...
Static block places lock for shorter periods in case of synchronization but static method places lock for longer

Related Tutorials/Questions & Answers: