摘录来自: (美)埃克尔 著 陈昊鹏 译. “java编程思想”。
那么潜在的问题是什么呢?再来看看代码:
abstract class Glypy { static int radius = 2; abstract void draw(); Glypy() { System.out.println("Glyph() before draw()"); draw(); System.out.println("Glypy() after draw()"); } } class RoundGlyph extends Glypy { int radius = 1; RoundGlyph(int r) { radius = r; System.out.println("RoundGlyph.RoundGlyph,radius= " + radius); } void draw() { System.out.println("RoundGlyph.draw(),radius=" + radius); } } public class PolyConstructors { public static void main(String[] args) { new RoundGlyph(5); } }
Glyph() before draw() RoundGlyph.draw(),radius=0 Glypy() after draw() RoundGlyph.RoundGlyph,radius= 5
那么如果既有继承又有静态属性静态等等这些呢。
静态属性(先父类后子类)->静态块(先父类后子类)->非静态属性(先父类后子类)->构造方法(先父类后子类)
原文地址:http://blog.csdn.net/tiantiandjava/article/details/46604739