标签:
package com.init;
abstract class Glyph {
void draw() {
System.out.println("Glyph.draw()");
}
Glyph() {
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph after draw()");
}
}
class RoundGlyph extends Glyph {
private int radius = 1;
RoundGlyph(int r) {
System.out.println("RoundGlyph.RoundGlyph().radius = " + radius);
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
Glyph after draw()
RoundGlyph.RoundGlyph().radius = 1
RoundGlyph.RoundGlyph().radius = 5
1 无继承情况下的Java初始化顺序:
标签:
原文地址:http://www.cnblogs.com/ziq711/p/5603453.html