почему статический блок в дочернем классе не выполняется?
вот код
public class ClassResolution {
static class Parent {
public static String name;
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);
}}
что я ожидаю, это:
this is Parent
this is Child
Child
но на самом деле это:
this is Parent
Parent
кажется, что статический блок в классе Child не выполняется, но почему? это не интуиция, не так ли?
supplement:
Чтобы было понятнее, я перечислю2 1 пункты ниже:
what do you think?
supplement2:
@ Алексей Кайгородов обновил свое мнение, так что, похоже, разногласий не осталось. Но я думаю, что точка зрения Алексея Кайгородова поучительна, поэтому я оставил это там.
Всем спасибо.