Given the following classes, complete the code for the Student class so that the following output is printed when we run the Q01 class. Hint: Student class is a child class of Person
Here is the output:
Department: CSE, ID: 20101001, Name: Mark Wahlberg
Department: BBA, ID: 20101002, Name: Zeeko Zaki
Department: CSE, ID: 20101002, Name: 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();
}
}
I created a new class below the class
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);
}
}
I cannot compile this code. How to solve this problem? where are my errors?