我在一个构造方法中调用第二个自身的构造方法,第二个自身构造方法中又包含一个super(),那么想知道在第一个自身构造方法中有没有隐式的super(),父类对象应该是优先于子类对象在堆内存里面出现的吧?最后究竟创建了几个父类对象
class Person {
private String name;
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 TestTeacher {
public static void main(String[] args) {
Student s1 = new Student("C","S1");
System.out.println(s1.info());
}}
android开发学习视频
相关分类