标签:super解疑
package Test;
public class TestExtends {
public static void main(String[] args) {
PersonB b = new PersonB();
System.out.println("============="+b.getName());
//PersonA a = new PersonA();
PersonA a = new PersonA("aaa");
//b.getName2("ddddd");
System.out.println("111111111111111"+a.getName());
}
}
class PersonA {
private String name;
//public static String name;加static可以使子类对父类的成员进行修改
public PersonA() {
System.out.println(getName());
}
public PersonA(String name) {
this.name = name;
System.out.println(getName());
}
public String getName() {
return name;
}
}
class PersonB extends PersonA {
public PersonB() {
// super();
super("小黑");
}
}
小结:
-运行结果--------------------------------------
小黑
=============小黑
aaa
111111111111111aaa
---------------------------------------------------标签:super解疑
原文地址:http://7122819.blog.51cto.com/7112819/1538632