Does creating a reference to an object of a class cause the class to be loaded ? Static variables are initialized when the class is loaded, so considering the following code
Yes. Static initializers are called when a class method is called or an instance is instantiated.
From your example you can do one of the following:
public static void main(String[] args) {
A a = new A();
}
public static void main(String[] args) {
int f = A.f();
}