public class Text {
public static void main(String[] args) {
Chila c = new Chila();
c.mention();
}
}
class Base {
String name;
public Base() {
name = "base";
}
public Base(String string) {
// TODO Auto-generated constructor stub
}
public void mention() {
System.out.println(name);
}
}
class Chila extends Base {
public Chila() {
super("Chila");
name = "bb";
}
}
改成这样就好了,在Base类里构造一个public Base(String string)方法,然后把在Base类的私有成员变量的关键字private去掉,你就能在下面定义name=“bb”了 |