在构造器中调用多态方法进行初始化,也许会产生不可预料的结果。
import java.io.FileWriter;
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
* User: wulong
* Date: 11-10-31
* Time: 上午1:56
* To change this template use File | Settings | File Templates.
*/
class Shap {
void set() {
try {
System.out.println("Shap.set()");
FileWriter fw = new FileWriter("hello.txt", true);
String s = "Shap.set\n";
fw.write(s);
fw.flush();
fw.close();
} catch (IOException e) {
System.out.println("Shap.set e=" + e.getMessage());
}
}
Shap() {
System.out.println("Shap().in=");
set();
System.out.println("Shap().out=");
}
}
class Line extends Shap {
int counter = 9;
void set() {
try {
System.out.println("Line.set() co