Java Program using static variables methods and blocks


In this program, You will learn how to implement static variables methods and blocks in Java.


static int x;

static void display() { }

static { }


Example: How to implement static variables methods and blocks in Java

Run it Now
class Main {

    static int x = 10;

    static {
        System.out.println("static block is called here");
    }

    static void display() {
        System.out.println("x value is :" + x);
    }

    public static void main(String args[]) {
        display();
    }
}

Output:

static block is called here
x value is :10