记下来只为给自己一个教训:
class="java">
class Base{
private String name = "base";
public Base() {
tellName();
printName(name);
}
public void tellName(){
System.out.println("Base tell: "+name);
}
public void printName(String name){
System.out.println("Base print: "+name);
}
}
public class Derived extends Base{
private String name = "derived";
public Derived() {
tellName();
printName(name);
}
public void tellName(){
System.out.println("Derived tell: "+name);
}
public void printName(String name){
System.out.println("Derived print: "+name);
}
public static void main(String[] args) {
new Derived();
}
}
输出:
Derived tell: null
Derived print: base
Derived tell: derived
Derived print: derived