6-1 根据父类完成子类 (10分)

it2026-09-29  9

裁判测试程序样例中展示的是一段定义基类People、派生类Student以及测试两个类的相关Java代码,其中缺失了部分代码,请补充完整,以保证测试程序正常运行。 函数接口定义:

观察类的定义和main方法中的测试代码,补全缺失的代码。 裁判测试程序样例:

class People{ private String id; private String name; public People(String id, String name) { this.id = id; this.name = name; } public String getId() { return id; } public String getName() { return name; } }

class Student extends People{ private String sid; private int score; public Student(String id, String name, String sid, int score) {

/** 你提交的代码将被嵌在这里(替换此行) **/ } public String toString(){ return ("(Name:" + this.getName() + "; id:" + this.getId() + "; sid:" + this.sid + "; score:" + this.score + ")"); }

} public class Main { public static void main(String[] args) { Student zs = new Student(“370202X”, “Zhang San”, “1052102”, 96); System.out.println(zs);

}

}

输入样例:

在这里给出一组输入。例如:

输出样例:

在这里给出相应的输出。例如:

(Name:Zhang San; id:370202X; sid:1052102; score:96)

super(id,name); this.sid=sid; this.score=score; this.toString();
最新回复(0)