import java.util.*;
import java.lang.*;
import java.io.*;

// from Java, The Complete Reference, 9th Edition.

class UseStatic {
    static int a = 3;
    static int b;
    
    public static void meth(int x) {
        System.out.println("x = " + x);
        System.out.println("a = " + a);
        System.out.println("b = " + b);
    }
    
    // called whenever any method or member of the class is used
    static {
        System.out.println("static block initialized");
        b = a * 4;
    }
    
    public static void main(String args[]) {
        meth(42);
    }
}

class Main {
    public static void main(String[] args) {
        // UseStatic.meth(42);
        System.out.println(UseStatic.b);
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: