Consider classes Person and Student as shown below, and the
following object declarations and instantiations:
-----------------------------------
public class Person
{
private long ssn;
private String name;
public Person(String name, long ssn)
{
this.name = name;
this.ssn = ssn;
}
public String toString()
{
return name + " " + ssn;
}
}
-----------------------------------
public class Student extends Person
{
double gpa;
//method definitions go here
}
-----------------------------------
- Write a constructor for the Student class that takes a name, ssn, and
gpa and sets up a new Student object accordingly. Remember that Student
is a subclass of Person.
- Write a toString method for the Student class that returns a string
containing the student's name, ssn, and gpa. Note that name and ssn
are private in Person.
- Suppose that object p is of type Person and object s is of type Student.
Tell whether each assignment below is legal:
- p = s;
- s = p;