Scenario 1 :
class A{
static int foo=56789;
static{
foo=999;
}
public static void main(String[] args) {
System.out.println(foo);
}
}
Output : 999
Scenario 2:
class A{
static {
foo=999;
}
static int foo=56789;
public static void main(String[] args) {
System.out.println(foo);
}
}
Output : 56789
In Scenario 2 how does it allocate memory to foo variable (in static block) as no data type is mentioned along with it(as the code runs from Top to Bottom).