The superclass Student contains: a constructor that accepts a String correspondi
ID: 3651400 • Letter: T
Question
The 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 class definition for the subclass HighSchoolStudent containing:
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.
Explanation / Answer
Student.java : public class Student { protected String school; public Student(String school) { this.school = school; } public String toString() { return "student at " + school; } } HighSchoolStudent.java : public class HighSchoolStudent extends Student { public HighSchoolStudent(String school) { super(school); } public String toString() { return "high school " + super.toString(); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.