I am learning the static block functionality in core java.
public class ClassResolution {
static class Parent {
public static String name = "Sparsh";
static {
System.out.println("this is Parent");
name = "Parent";
}
}
static class Child extends Parent {
static {
System.out.println("this is Child");
name = "Child";
}
}
public static void main(String[] args) throws ClassNotFoundException {
System.out.println(Child.name);
}
}
I thought the output would be:
this is Parent
this is Child
Child
but the actual output is:
this is Parent
Parent
and I have no idea why.