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 staticRight