3. Static blocks in Java:
Static blocks are called before the main block is called.It can initialize the static data members.
Example:
public class HelloWorld{
static double pi = 3.14;
static{System.out.println("static block is invoked");}
public static void main(String[] args) {
System.out.println("main block");
}
}
No comments:
Post a Comment