course | mod | topic | first name | date completed |
---|---|---|---|---|
cit-130 | wk. 2 | inheritance basics | ||
module learning objectives | ||||
|
program objective |
Demonsrate the essential elements of inheritance: subclasses, superclasses, and typing |
requirements |
Create a Student superclass, an EleSchoolStudent subclass, a HSStudent subclass, and a CollegeStudent subclass of Student Create appropriate member variables for each subclass that store information relevant to these categories of students. For example, a HSStudent might store a reference to their class schedule, but an elementary student would not be tracking her own schedule. Create an array of Student objects. Generate at least two instances of each subclass of Student and store them in the array. Write a method for each subclass that prints out characteristics that ony exist on that student, AS WELL AS the member variables stored on the super class. So a method called displayHSStudentinfo(HSStudent stud) will display the student's name, id number (both on the superclass) and the HSStudent's schedule or if the student is college-interested or not. Create a for() loop that iterates over each student and uses the instanceof operator to check for the subclass type. Using a switch statement, farm out the object you just pulled out of the array to the appropraite method based on the type you discovered using instanceof. |