分类: Java
2005-05-21 18:58:39
public class Class_one {
public String str = "one";
protected String getNumber() {
return str;
}
public static void main(String args[]) {
Class_one a = new Class_one();
System.out.println(a.getNumber());
}
}
public class Class_two extends Class_one {
public String str = "two";
protected String getNumber() {
return super.str;
}
public static void main(String args[]) {
Class_two b = new Class_two();
System.out.println(b.getNumber());
}
}
public class Class_three extends Class_two {
public String str = "three";
protected String getNumber() {
return super.str;
}
public static void main(String args[]) {
Class_three c = new Class_three();
System.out.println(c.getNumber());
}
}
问题:Class_three 中的getNumber()可以不override么?为什么?
public class Class_one {
private String str = "one";
protected String getNumber() {
return str;
}
public static void main(String args[]) {
Class_one a = new Class_one();
System.out.println(a.getNumber());
}
}
public class Class_two extends Class_one {
private String str = "two";
protected String getNumber() {
return super.getNumber();
}
public static void main(String args[]) {
Class_two b = new Class_two();
System.out.println(b.getNumber());
}
}
public class Class_three extends Class_two {
private String str = "three";
protected String getNumber() {
return super.getNumber();
}
public static void main(String args[]) {
Class_three c = new Class_three();
System.out.println(c.getNumber());
}
}
这样呢?
结果有什么区别?
呵呵