public class Person
{
private String firstName;
private String lastName;
public Person(String pFirstName, String pLastName)
{
firstName = pFirstName;
lastName = pLastName;
}
public void personInfo()
{
System.out.println("My name is " + firstName + " " + lastName);
}
}
pubic class Teacher extends Person
{
private String school;
private String subject;
public Teacher(String tFN, String tLN, String tSchool, String tSubject)
{
super(tFN, tLN);
school = tSchool;
subject = tSubject;
}
public void teacherInfo()
{
personInfo();
System.out.println("I teach " + subject + " at " + school);
}
}
The following code segment appears in a class other than Person or Teacher.
Person teach = new Teacher("Henry", "Lowe", "PS 150", "English");
teach.teacherInfo();
Which of the following best explains why the code segment will not compile?
A. The call to personInfo(); in the teacherInfo method should be this.personInfo(); because personInfo is a method in the Person class.
B. The personInfo method should be moved to the Teacher class because personInfo is a method only in the Person class.
C. The teacherInfo method should be moved to the Person class because teacherInfo is a method in the Teacher class.
D. The variable teach should be declared as a Teacher data type because teacherInfo is a method in the Teacher class.
E.The variable teach should be instantiated as a Person object because teach has been declared as type Person.