he superclass Student contains: a constructor that accepts a String corresponding to the name of the school the student attends a toString method that returns 'student at X' where X is the name of the school the student attends. Write a public subclass HighSchoolStudent, based on Student, which contains: a constructor accepting a String which is used as a parameter to the superclass constructor a toString method that returns 'high school student at X'. This method must use the toString method of its superclass.

Respuesta :

Solution :

public [tex]$\text{class}$[/tex] Student {

[tex]$\text{protected String}$[/tex] school[tex]$;$[/tex]

public [tex]$\text{Student}$[/tex](String school) {

[tex]$\text{this.school}$[/tex] = school;

}

public String [tex]$\text{toString}()$[/tex] {

return [tex]$\text{"student at"}$[/tex] + school;

}

}

HighSchool[tex]$\text{Student.java}$[/tex] :

public class [tex]$\text{HighSchoolStudent}$[/tex] extends Student {

public [tex]$\text{HighSchoolStudent}$[/tex](String school) {

super[tex]$\text{(school)}$[/tex];

}

public String [tex]$\text{toString}()$[/tex] {

return [tex]$\text{"high school"}$[/tex] + super.[tex]$\text{toString}()$[/tex];

}

}

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE