The order of running Java class

Posted on 2007-11-17 03:34  QT_pixy  阅读(226)  评论(0)    收藏  举报
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.

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3