When I invoke the static variable y by using Checks.y (Checks being a subclass), the static block is not executed and the value of y doesn't get updated.
class Par {
static int y = 4;
}
class Checks extends Par {
static {
y = 5;
}
}
public class Check {
public static void main(String args[]) {
System.out.println(Checks.y); // here printing 4
}
}
As static is shared among all subclasses, the value is supposed to be updated.
What could be the reason behind it?