abstract class Person {
private String name;
private int age;
private String id;
private double mouth;
Person(String name,int age,String id,double mouth){
this.name=name;
this.age=age;
this.id=id;
this.mouth=mouth;
}
abstract void work();
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
public void setMouth(double mouth){
this.mouth=mouth;
}
}
***************************************************************************
public class Manager extends Person{
Manager(String name,int age,String id,double mouth){
super(name,age,id,mouth);
}
public void work(){
}}
为什么子类继承父类,子类的构造函数就一定要带参数呢?
private String name;
private int age;
private String id;
private double mouth;
Person(String name,int age,String id,double mouth){
this.name=name;
this.age=age;
this.id=id;
this.mouth=mouth;
}
abstract void work();
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
public void setMouth(double mouth){
this.mouth=mouth;
}
}
***************************************************************************
public class Manager extends Person{
Manager(String name,int age,String id,double mouth){
super(name,age,id,mouth);
}
public void work(){
}}
为什么子类继承父类,子类的构造函数就一定要带参数呢?
super();
}这样就不需要参数了,楼主该看看有关继承的一些基础知识
呵呵,是啊,如果你的父类没有参数而你的子类使用 super()硬是要写参数,你觉得是对的吗?