@Slf4j
public class TestA {
public static Integer age = getAge();
static{
log.info("static a");
}
public TestA() {
log.info("test a");
}
private static Integer getAge(){
log.info("test a.age");
return 1;
}
}
子类
@Slf4j
public class TestB extends TestA{
public static Integer age = getAge();
static{
log.info("static b");
}
public TestB() {
log.info("test b");
}
private static Integer getAge(){
log.info("test b.age");
return 1;
}
}
测试类
public static void main(String[] args) {
new TestB();
}
输出结果:
2021-02-06 18:22:00,789 INFO - test a.age
2021-02-06 18:22:00,789 INFO - static a
2021-02-06 18:22:00,789 INFO - test b.age
2021-02-06 18:22:00,789 INFO - static b
2021-02-06 18:22:00,789 INFO - test a
2021-02-06 18:22:00,789 INFO - test b