大家帮我看一下,在super()函数前加this()编译都不能通过,去掉this()就没问题,为什么呢?
下面是源代码,大家可以跑得看一下 ,谢谢
package TestDemo;
class Person{
String name;
int age;
String address;
Person(){
System.out.println("我是父类无参构造方法。");
}
Person(int age,String name,String address){
this.age=age;
this.name=name;
this.address=address;
System.out.println("我是父类有参构造方法。");
}
void tell(){
System.out.println("我是父类的tell方法。");
}
}
class Student extends Person{
int score;
Student(){
System.out.println("我是子类无参构造方法。");
}
Student(int age,String name,String address,int score){
this();
super(age,name,address);
super.tell();
System.out.println("我是子类有参构造方法");
System.out.println("大家好,我叫"+name+",我今年"+age+"岁,家住"+address+",今天考试我考了"+score+"分!");
}
}
public class Test02 {
public static void main(String[] args) {
new Student();
new Student(20,"张三","北京",100);
}
}