public class S
{
public static void main(String[] args)
{
ClassManage monitor = new ClassManage("Tom", "20031009", "班长");
ClassPE player= new ClassPE("CS","333","组长","选手");
Student[] student = new Student[4];
student[0] = monitor;
student[1] = player;
student[2] = new Student("Jack", "2003100901");
student[3] = new Student("Rose", "2002091002");
for(int i = 0; i <student.length; i++)
{
System.out.println(student[i].toString());
}
}
}
class Student
{
private String strName = "";
private String strNumber = "";
private String strSex = "";
private String strBirthday = "";
private String strSpeciality = "";
private String strAddress = "";
public Student(String name, String number)
{
strName = name;
strNumber = number;
}
public String getStudentName()
{
return strName;
}
public String getStudentNumber()
{
return strNumber;
}
public void setStudentSex(String sex)
{
strSex = sex;
}
public String getStudentSex()
{
return strSex;
}
public String getStudentBirthday()
{
return strBirthday;
}
public void setStudentBirthday(String birthday)
{
strBirthday = birthday;
}
public String getStudentSpeciality()
{
return strSpeciality;
}
public void setStudentSpeciality(String speciality)
{
strSpeciality = speciality;
}
public String getStudentAddress()
{
return strAddress;
}
public void setStudentAddress(String address)
{
strAddress = address;
}
public String toString()
{
String information = "学生姓名=" + strName + ", 学号=" + strNumber;
if( !strSex.equals("") )
information += ", 性别=" + strSex;
if( !strBirthday.equals(""))
information += ", 出生年月=" + strBirthday;
if( !strSpeciality.equals("") )
information += ", 专业=" + strSpeciality;
if( !strAddress.equals("") )
information += ", 籍贯=" + strAddress;
return information;
}
}
class ClassManage extends Student
{
private String strDuty = "";
public ClassManage(String name, String number, String strDuty)
{
super(name, number);
this.strDuty = strDuty;
}
public String getDuty()
{
return strDuty;
}
public String toString()
{
String str = super.toString();
if(!strDuty.equals(""))
{
str += ", 职务=" + strDuty;
}
return str;
}
}
class ClassPE extends ClassManage
{
private String strPE ="";
public ClassPE(String name,String number,String strDuty, String strPE);
{
super(name,number,strDuty);
this.strPE=strPE;
}
public String getPE()
{
return strPE;
}
public String toString()
{
String str= super.toString();
if(!strPE.equals(""))
{
str +=",体=" + strPE;
}
return str;
}
}
最后一个类是我完全按照上一个类写的,为什么可编译,无法运行?
ClassPE可以继承Student的方法吗?
D:\>javac S.java
S.java:143: missing method body, or declare abstract
public ClassPE(String name,String number,String strDuty, String strPE);
^
S.java:145: call to super must be first statement in constructor
super(name,number,strDuty);
^
2 errors
谢谢。