public class Apple extends Fruit {
private String name = "apple";
public Apple () {
tellName();
printName();
}
public void tellName() {
System.out.println("Apple tell name: " + name);
}
public void printName() {
System.out.println("Apple print name: " + name);
}
public static void main(String[] args){
new Apple();
}
}
class Fruit {
private String name = "fruit";
public Fruit () {
tellName();
printName();
}
public void tellName() {
System.out.println("fruit tell name: " + name);
}
public void printName() {
System.out.println("fruit print name: " + name);
}
}
我想知道为什么会输出4行
以及什么原因
感谢各位