谁告诉你构造代码块优先于构造方法的?
- public class Test {
- public static void main(String[] args){
- new B();
- }
- }
- class A {
- public A() {
- System.out.println("A's constructor");
- }
-
- }
- class B extends A {
- {
- System.out.println("B's initialization block");
- }
-
- public B() {
- System.out.println("B's constructor");
- }
-
- }
复制代码
输出结果是:
A's constructor
B's initialization block
B's constructor
|