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 {
static{
System.out.println("Hello");
}
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(){
System.out.println("Hello");
}
static void testStaticMethod(){
printString();
}
public static void main(String args[]){
testStaticMethod();
}
}
static block is used to initialize the variables during the
JVM startup.
static methods are getting called with out creation of any
instance.
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 :
http://www.roseindia.net/java/beginners/http://www.roseindia.net/java/beginners/howtoaccessstaticmethod.shtmlThanks