java 子类中this,请问子类中的构造方法中 this(name,beijing,school);是啥意思
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
private String location;
Person(String name){
this.name=name;
location="beijing";
}
Person(String name,String location){
this.name=name;
this.location=location;
}
public String info(){
return "name:"+name+ "location:"+location;
}
}
class Student extends Person{
private String school;
Student (String name,String school){
this(name,"beijing",school);
}
Student (String n,String l,String school){
super (n,l);
this.school=school;
} public String info(){
return super.info()+"school:"+school;
}
}
public class Test{
public static void main(String[] args){
Person p1= new Person("A");
Person p2= new Person("B","shanghai");
Student s1= new Student("C","s1");
Student s2 =new Student("C","shanghai","s1");
System.out.println(p1.info());
System.out.println(p2.info());
System.out.println(s1.info());
System.out.println(s2.info());
}
}
總結
以上是生活随笔為你收集整理的java 子类中this,请问子类中的构造方法中 this(name,beijing,school);是啥意思的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php漏洞论坛,PHPWind超级漏洞简
- 下一篇: Java为什么会存成undefined,