When you run your Java programs which contain one or more classes, you may get some strange problems or errors. Not all errors are made by syntax fault. You have to consider the basic principle of running a Java class. The order is important and people always pay less attention on it.
Here is the order.
step 1:
Initialize static fields. From base class to derived class.
step 2:
Call constructors of super classes. From derived class to base class.
step 3:
Initialize fields and run constructors. From base class to derived class.
Here is the order.
step 1:
Initialize static fields. From base class to derived class.
step 2:
Call constructors of super classes. From derived class to base class.
step 3:
Initialize fields and run constructors. From base class to derived class.
浙公网安备 33010602011771号