course mod topic first name date completed
cit-130 wk. 2 inheritance basics
module learning objectives
  • TR.130.2.L.1: Create a two-class object hierarchy and demonstrate accessing a parent's data from the child
  • TR.130.2.L.2: Demonstrate a core feature of inheritance by storing and manipulating an object reference to a child class in a variable typed to the parent
  • TR.130.2.L.3: Write a program that uses Object-type variables and type casting to manipulate objects in a sample class hierarchy
Caption text caption link text
java master sequence > inheritance basics

Inheritance basics

  1. Create a class diagram of our student objects, showing each object's parent
  2. Write code in Java that demonsrates that a variable typed to the parent can store references to the children

Mini-program specification

program objective

Demonsrate the essential elements of inheritance: subclasses, superclasses, and typing


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.