X776: Polymorphism Practice 1

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;
    }
}

Write a method that takes in two variables: one of type Person, one of type Student. This code should assign the object where age is larger to the variable max defined below, then return max.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.