qq_38364114 2017-04-27 13:28 采纳率: 0%
浏览 782
已采纳

程序没问题,可我想问的是为什么不能执行

public class SchoolTest {
public static void mian (String[]args){
Student st1=new Student ();
Student st2=new Student ();
Teacher te1=new Teacher ();
Teacher te2=new Teacher ();
st1.setschoolname ("重庆大学");
st1.setclassname ("计算机二班");
st1.setname ("王刚");
st1.setcode ("951034");
st1.setsex ("男");
st1.setbirthday ("1975-07-21");
st1.setfamilyaddress ("上海浦东新区");
//我是分隔符╮(╯▽╰)╭
st2.setschoolname ("重庆大学");
st1.setclassname ("计算机三班");
st1.setname ("谢娜");
st1.setcode ("951068");
st1.setsex ("女");
st1.setbirthday ("1975-10-09");
st1.setfamilyaddress ("北京海淀区");
//我是分隔符╮(╯▽╰)╭
te1.setschoolname ("四川大学");
te1.setclassname ("计算机二班");
te1.setname ("赵敏");
te1.setcode ("001234");
te1.setsex ("女");
te1.setbirthday ("1968-04-20");
te1.setfamilyaddress ("重庆市沙坪坝区");
//我是分隔符╮(╯▽╰)╭
te2.setschoolname ("四川大学");
te2.setclassname ("机械系三班");
te2.setname ("赵日天");
te2.setcode ("000001");
te2.setsex ("男");
te2.setbirthday ("1961-02-13");
te2.setfamilyaddress ("成都市区");
//我是分隔符╮(╯▽╰)╭
System.out.println (st1.toString ());
System.out.println (st2.toString ());
System.out.println (te1.toString ());
System.out.println (te2.toString ());
}
}

  • 写回答

9条回答 默认 最新

  • hxy15918436902 2017-04-27 15:12
    关注

    public class School {
    private String schoolName;
    private String className;
    private String name;
    private String code;
    private String sex;
    private String birthday;
    private String address;
    public School() {
    super();
    }
    public School(String schoolName, String className, String name, String code, String sex, String birthday,
    String address) {
    super();
    this.schoolName = schoolName;
    this.className = className;
    this.name = name;
    this.code = code;
    this.sex = sex;
    this.birthday = birthday;
    this.address = address;
    }

    public String getSchoolName() {
        return schoolName;
    }
    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }
    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getBirthday() {
        return birthday;
    }
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    

    }


    public class Student extends School{
    public Student(){
    super();
    }
    public Student(String schoolName, String className, String name, String code, String sex, String birthday,
    String address){
    super(schoolName,className, name, code, sex, birthday,
    address);
    }
    @Override
    public String toString() {
    return "学校名称:"+this.getSchoolName()+","+"班级名称"+this.getClassName()+","
    +"学生姓名"+this.getName()+","+"学号:"+this.getCode()+","
    +"性别:"+this.getSex()+","+"出生年月:"+this.getBirthday()+","
    +"家庭住址:"+this.getAddress();
    }

    }

    public class Teacher extends School{
    public Teacher(){
    super();
    }
    public Teacher(String schoolName, String className, String name, String code, String sex, String birthday,
    String address){
    super(schoolName,className, name, code, sex, birthday,
    address);
    }
    @Override
    public String toString() {
    return "学校名称:"+this.getSchoolName()+","+"班级名称"+this.getClassName()+","
    +"教师姓名"+this.getName()+","+"教师工号:"+this.getCode()+","
    +"性别:"+this.getSex()+","+"出生年月:"+this.getBirthday()+","
    +"家庭住址:"+this.getAddress();
    }

    }

    public class Test {
    public static void main(String[] args) {
    School[] s = new School[4];
    s[0]= new Student("重庆大学","计算机二班","王刚","951034","男","1975-07-21","上海浦东新区");
    s[1]= new Student("重庆大学","计算机二班","谢娜","951034","女","1976-07-21","北京海淀区");
    s[2]= new Teacher("四川大学","计算机二班","赵敏","951034","女","1975-07-21","上海浦东新区");
    s[3]= new Teacher("四川大学","计算机二班","赵日天","951034","男","1975-07-21","上海浦东新区");
    for(School temp : s){
    System.out.println(temp);
    }
    }

    }

    我帮你优化了一下你的程序,你可以试着看看我们两个的程序有什么不一样。都做到这地步了你忍心不采纳吗?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮