public static void main(String[] args)
{
Student st=new Student();
System.out.println(st.name+","+st.age+","+st.id);
}
class Person
{
int age;
String name;
Person(int age,String name)
{
this.age=age;
this.name=name;
}
}
class Student extends Person
{
int id;
int age;
String name;
Student()
{
this(10);//this掉用本类的相关的构造方法,也必须是第一句
}
Student(int id)
{
super(20,"tom");//必须是第一句,super()调用父类的构造函数
this.id=id;
}
}
解释下上面程序的执行过程和结果! |