You have a single object.
When an instance of the class is created, it calls the first constructor of the parent class. And for each parent class, it follows the same logic: it calls the first constructor of the parent class.
Suppose: Aextends Bextends C.
new A() B, C.
C B, A , A.
, .
first .
, A extends B extends C:
class C {
public C(){
System.out.println("C constructor");
}
}
class B extends C{
public B() {
System.out.println("B constructor");
}
}
class A extends B{
public A() {
System.out.println("A constructor");
}
}
public class Test {
public static void main(String[] args) {
new A();
}
}
Test, A main(), -verbose ( ) java:
java -verbose Test
- :
[Loaded java.lang.Object from C:\...]
[Loaded java.io.Serializable from C:\...]
... // load all classes required until loaded C, B and A classes
[Loaded C from file:/C:/...]
[Loaded B from file:/C:/...]
[Loaded A from file:/C:/...]
C constructor
B constructor
A constructor
, :
- , (
Object) (B). - , (
Object) (B).