给定以下类,完成 Student 类的代码,以便在我们运行 Q01 类时打印以下输出。提示:学生类是 Person 的子类
这是输出:
部门:CSE,ID:20101001,姓名:Mark Wahlberg
部门:BBA,ID:20101002,姓名:Zeeko Zaki
部门:CSE,编号:20101002,姓名:Zeeko Zaki
public abstract class Person {
private String name;
private Person() {
}
Person(String name) {
this.name = name;
}
protected String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
}
public class Q01 {
public static void main(String[] args) {
Student s1 = new Student("CSE", 20101001, "Mark Wahlberg");
Student s2 = new Student("BBA", 20101002, "Zeeko Zaki");
s1.printDetail();
s2.printDetail();
s2.setDepartment("CSE");
s2.printDetail();
}
}
我在班级下面创建了一个新班级
public class Student extends Person{
public String department="";
public int id;
public String name;
public String Public(String name){
return name;
}
public Student(String department,int id,String name){
this.department=department;
this.id=id;
this.name=name;
}
public void setDepartment(String department){
this.department=department;
}
public String getDepartment(){
return department;
}
public void printDetail(){
System.out.println("Department: "+this.department+", ID: "+this.id+", Name: "+name);
}
}
我无法编译这段代码。如何解决这个问题呢?我的错误在哪里?
慕姐4208626
相关分类