class revi {
static {
i = 3;
System.out.println("Hello World!");
}
static int i = 15;
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
above program does not give any error at i=3; but when we call the i in println() method of static block it showing error
revi.java:6: error: illegal forward reference System.out.println("Hello World!"+i); ^ 1 error
class revi {
static {
i = 3;
System.out.println("Hello World!" + i);
}
static int i = 15;
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
but if modify the above program like this it working(static variable first loaded ) no error in println method
class revi {
static int i = 15;
static {
i = 3;
System.out.println("Hello World!" + i);
}
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
please explain internal flow ...