My Hindi Forum

My Hindi Forum (http://myhindiforum.com/index.php)
-   Tech Talks (http://myhindiforum.com/forumdisplay.php?f=20)
-   -   What is difference between static and init block in java? (http://myhindiforum.com/showthread.php?t=178)

rajesh 13-01-2010 10:47 AM

What is difference between static and init block in java?
 
The static block is only loaded when the class object is created by the JVM for the first time whereas init block is loaded every time class object is created. Also first the static block is loaded then the init block.

Code:

public class LoadingBlocks {

static{
System.out.println("Inside static");
}

{
System.out.println("Inside init");
}
public static void main(String args[]){
new LoadingBlocks();
new LoadingBlocks();
new LoadingBlocks();
}
}

Output will be :

Inside static
Inside init
Inside init
Inside init


All times are GMT +5. The time now is 12:47 PM.

Powered by: vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
MyHindiForum.com is not responsible for the views and opinion of the posters. The posters and only posters shall be liable for any copyright infringement.