Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Каков порядок вызова конструкторов и блоков инициализации с учётом иерархии классов? #74

Open
Niro opened this issue Apr 19, 2021 · 0 comments

Comments

@Niro
Copy link

Niro commented Apr 19, 2021

Необходимо поменять вопрос или ответ на него, либо добавить пояснение. Если спрашиваем про порядок вызова, то сначала вызывается конструктор самого младшего и далее выше по иерархии, но выполняются они в том порядке, какой написан в ответе. В дебагере порядок вызова виден.

public class A extends B {
    public A() {
        super("From A");
        System.out.println(", но выполняются от самого старшего к самому младшему");
    }
}
public class B extends C {
    public B(String param) {
        super("From B");
        System.out.print(" самого младшего к самому старшему");
    }
}
public class C {
    public C(String param) {
        System.out.print("На самом деле вызываются от");
    }
}

Screenshot 2021-04-19 at 20 57 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant