- class Person {
- String name;
- int age;
- Person(String name,int age)
- {
- this.name = name;
- this.age = age;
- }
- }
复制代码- public class Student extends Person{
- int num;
- Student(String name,int age)
- {
- super(name,age);
- }
- Student(String name)
- {
- this.num = num;
- }
- Student()
- {
- }
- public void studey()
- {
- System.out.println("study");
- }
- }
复制代码
为什么Student继承了Person之后就子类就不能在写别的构造函数了。比如Student(){} 和Student(String name)
{
this.num = num;
}
这2句代码就会报错 为什么呢??
|
|