public class Parent {
public static int y=10 ;
}
public class Child extends Parent {
static {
y=20 ;
}
public static void main(String[] args) {
System.out.println(Child.y); // output = 20
}
}
public class Test {
public static void main(String[] args) {
System.out.println(Child.y); // output = 10
}
}
Note: in the first scenario, static block is getting executed. But this is not the same case in the second scenario. Why? Why does the output value differ? I am using jdk-17