运行报错,这为啥呀,弄好几个小时了/(ㄒoㄒ)/~~
代码:
package test0420;
abstract class Person {
protected String name;
protected String sex;
protected String birth;
public Person() {}
public Person(String name,String sex,String birth) {
this.name=name;
this.sex=sex;
this.birth=birth;
}
public String toString() {
return "姓名:"+name+",性别:"+sex+",出生日期:"+birth;
}
}
class Teacher extends Person{
private String school;
private String kind;
public Teacher(String name,String sex,String birth,String school,String kind) {
super(name,sex,birth);
this.school=school;
this.kind=kind;
}
public String toString() {
return super.toString()+",任课学校:"+school+",类别:"+kind;
}
}
abstract class Student extends Person{
protected String school;
protected int sno;
protected String grade;
public Student () {}
public Student (String name,String sex,String birth,String school,int sno,String grade) {
super(name,sex,birth);
this.school=school;
this.sno=sno;
this.grade=grade;
}
public String toString() {
return super.toString()+",学校"+school+",学号:"+sno+",年级:"+grade;
}
}
class College extends Student{
private String major;
public College() {}
public College(String name,String sex,String birth,String school,int sno,String grade,String major) {
super(name,sex,birth,school,sno,grade);
this.major=major;
}
public String toString() {
return super.toString()+",专业:"+major;
}
}
class Middle extends Student{
public Middle() {}
public Middle(String name,String sex,String birth,String school,int sno,String grade) {
super(name,sex,birth,school,sno,grade);
}
public String toString() {
return super.toString();
}
class Primary extends Student{
public Primary() {}
public Primary(String name,String sex,String birth,String school,int sno,String grade) {
super(name,sex,birth,school,sno,grade);
this.school=school;
}
public String toString() {
return super.toString();
}
}
public class Test{
public void main(String[] args) {
Teacher t[]=new Teacher[2];
t[0]= new Teacher("王老师", "女", "1991年5月3日", "南昌交通学院", "大学");
t[2]= new Teacher("李老师", "男", "1981年8月5日", "实验小学", "小学");
System.out.println(t.toString());
College c[]=new College[3];
c[0]= new College("张三", "男","2003年7月9日", "南昌大学",001, "大二", "计算机");
c[1]= new College("李四", "男","2001年6月12日", "南昌交通学院",045, "大四", "软件工程");
c[2]= new College("黄玲", "女","2003年12月4日", "厦门大学",076, "大一", "英语");
System.out.println(c.toString());
Middle m[]=new Middle[3];
m[0]= new Middle("李华", "女","2004年11月8日", "永新中学",024, "高三");
m[1]= new Middle("尹龙", "男","2003年6月15日", "永新二中",024, "高二");
m[2]= new Middle("陈萧", "男","2003年3月6日", "禾川中学",024, "高一");
System.out.println(m.toString());
Primary p[]=new Primary[3];
p[0]= new Primary("黄栗","女","2012年6月30日","城厢小学",034,"三年级");
p[1]= new Primary("陈泽","男","2010年5月18日","城南小学",024,"一年级");
System.out.println(p.toString());
}
}
报错:
package test0420;
import java.util.Arrays;
/**
* @author huazie
* @version 2.0.0
* @since 2.0.0
*/
abstract class Person {
protected String name;
protected String sex;
protected String birth;
public Person() {
}
public Person(String name, String sex, String birth) {
this.name = name;
this.sex = sex;
this.birth = birth;
}
public String toString() {
return "姓名:" + name + ",性别:" + sex + ",出生日期:" + birth;
}
}
class Teacher extends Person {
private String school;
private String kind;
public Teacher(String name, String sex, String birth, String school, String kind) {
super(name, sex, birth);
this.school = school;
this.kind = kind;
}
public String toString() {
return super.toString() + ",任课学校:" + school + ",类别:" + kind;
}
}
abstract class Student extends Person {
protected String school;
protected int sno;
protected String grade;
public Student() {
}
public Student(String name, String sex, String birth, String school, int sno, String grade) {
super(name, sex, birth);
this.school = school;
this.sno = sno;
this.grade = grade;
}
public String toString() {
return super.toString() + ",学校" + school + ",学号:" + sno + ",年级:" + grade;
}
}
class College extends Student {
private String major;
public College() {
}
public College(String name, String sex, String birth, String school, int sno, String grade, String major) {
super(name, sex, birth, school, sno, grade);
this.major = major;
}
public String toString() {
return super.toString() + ",专业:" + major;
}
}
class Middle extends Student {
public Middle() {
}
public Middle(String name, String sex, String birth, String school, int sno, String grade) {
super(name, sex, birth, school, sno, grade);
}
public String toString() {
return super.toString();
}
}
class Primary extends Student {
public Primary() {
}
public Primary(String name, String sex, String birth, String school, int sno, String grade) {
super(name, sex, birth, school, sno, grade);
this.school = school;
}
public String toString() {
return super.toString();
}
}
public class Test {
public static void main(String[] args) {
Teacher t[] = new Teacher[2];
t[0] = new Teacher("王老师", "女", "1991年5月3日", "南昌交通学院", "大学");
t[1] = new Teacher("李老师", "男", "1981年8月5日", "实验小学", "小学");
System.out.println(Arrays.toString(t));
College c[] = new College[3];
c[0] = new College("张三", "男", "2003年7月9日", "南昌大学", 001, "大二", "计算机");
c[1] = new College("李四", "男", "2001年6月12日", "南昌交通学院", 045, "大四", "软件工程");
c[2] = new College("黄玲", "女", "2003年12月4日", "厦门大学", 076, "大一", "英语");
System.out.println(Arrays.toString(c));
Middle m[] = new Middle[3];
m[0] = new Middle("李华", "女", "2004年11月8日", "永新中学", 024, "高三");
m[1] = new Middle("尹龙", "男", "2003年6月15日", "永新二中", 024, "高二");
m[2] = new Middle("陈萧", "男", "2003年3月6日", "禾川中学", 024, "高一");
System.out.println(Arrays.toString(m));
Primary p[] = new Primary[3];
p[0] = new Primary("黄栗", "女", "2012年6月30日", "城厢小学", 034, "三年级");
p[1] = new Primary("陈泽", "男", "2010年5月18日", "城南小学", 024, "一年级");
System.out.println(Arrays.toString(p));
}
}