X457: PolymorphismPractice1

For this question, assume the following implementation of the Person and Student classes:

Person Class Implementation

public class Person{
    private String name;
    private int age;
    private double heightInCM;

    public Person (String na, int ag, double he) {
        name  = na;
        age = ag;
        heightInCM = he;
    }

    public String getName() {
        return name;
    }
    public int getAge() {
        return age;
    }
    public double getHeightInCM() {
        return heightInCM;
    }
}

Student Class Implementation

public class Student extends Person {
    private int studentID;
    private String school;

    public Student(String na, int ag, double he, int sId, String sch) {
        super(na, ag, he);
        studentID = sId;
        school = sch;

    }

    public int getStudentID() {
        return studentID;
    }


    public String getSchool() {
        return school;
    }
}

Below is a method that will take two person objects in as parameters. It should return a String array of size four that contains the names and schools (if they exist) of those objects.

For example, if two Person objects are passed in, the method should return the following array: ["PersonAName", "PersonBName", "", ""]

If two Student objects are passed in, the method should return the following array: ["PersonAName", "PersonBName", "PersonASchool", "PersonBSchool"]

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.