Best Blogger Tips

Wednesday 19 June 2013

Static block in Java


Static block

Static blocks in Java are initialize before any objects.They can access only static data types that are declared global or are instance variables. But can declare local variables of non-static within their scope.

Example


public class StaticDemonstration {

 static int a;
 static{
  System.out.println("Hello Static");
  a=10;
 int b = 10;
 System.out.println(a==b ? "Right":"Wrong");
 }
 
 public static void main(String[] args) {
 //No Objects
 }

}

Output

Hello static
Right

Kindly Bookmark this Post using your favorite Bookmarking service:
Technorati Digg This Stumble Stumble Facebook Twitter
YOUR ADSENSE CODE GOES HERE

0 comments:

Blogger Tricks And TipsComment here

 

| Bloggers Broadcast © 2010. All Rights Reserved | Back To Top |

Your Text Link Here