113k views
4 votes
Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code: Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1 p2 = new Student(); m2 = p2.getMoney(); // assignment 2 p3 = new Employee(); m3 = p3.getMoney(); // assignment 3 The reference to getMoney in assignment 3 is to the ________ class.

User Andromida
by
4.3k points

1 Answer

2 votes

Answer:

Person p1, p2, p3;

int m1, m2, m3;

p1 = new Person();

// assignment 1

m1 = p1.getMoney();

p2 = new Student();

// assignment 2

m2 = p2.getMoney();

p3 = new Employee();

// assignment 3

m3 = p3.getMoney();

//////////////////////////////////////////////////////////////////////////////////////////////

The reference to getMoney in assignment 3 is to the Person class.

Step-by-step explanation:

Since Employee class didn't override Person class's getMoney() method, calling p3 with getMoney() will call Base class's (Person) getMoney() method.

User Alex Pereira
by
3.7k points