2.4k views
1 vote
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.

User XiB
by
7.6k points

1 Answer

0 votes

Solution :

public
$\text{class}$ Student {


$\text{protected String}$ school
$;$

public
$\text{Student}$(String school) {


$\text{this.school}$ = school;

}

public String
$\text{toString}()$ {

return
$\text{ + school;

}

}

HighSchool
$\text{Student.java}$ :

public class
$\text{HighSchoolStudent}$ extends Student {

public
$\text{HighSchoolStudent}$(String school) {

super
$\text{(school)}$;

}

public String
$\text{toString}()$ {

return
$\text{ + super.
$\text{toString}()$;

}

}

User MadHatter
by
7.4k points