Static blocks are a powerful tool in Java programming and can be used to execute code before the main method of a class is called. In this article, we will explore what static blocks are and how they can be used to make your code more efficient and effective.
Here is the program
----------------------------------------------------
// Java program to demonstrate that static
// block is executed before main()
class staticExample {
// static block
static
{
System.out.println("Inside Static Block.");
}
// main method
public static void main(String args[])
{
System.out.println("Inside main method.");
}
}
----------------------------------------------------
Output
Inside Static Block.
Inside main method.
Comments
Post a Comment