Use the following code fragments for the next 3 questions As

Use the following code fragments for the next 3 questions. Assume that: . student. Empileves, and Betired are all child classes of Peraen Student, Employee, and Retired are all child classes of Person All four classes have different implementations of a method called getMoney Person p1 = new Person( ); int m1 =p1.getMoney(); // statement 1 Person p2 = new Student (. . .) ; int m2 = p2.getMoney ( ); // statement2 Person p3; if (m2

Solution

Given :-

Person p1 = new Person ( );
int m1 = p1.getMoney ( ); // statement1

Person p2 = new Student ( );
int m2 = p2.getMoney ( ); // statement2

Person p3;
if(m2 < 100000)
{
p3 = new Employee( );   
}
else
{
p3 = new Retired( );
}
int m3 = p3.getMoney ( ); // statement3

Question 50 :-

statement1 :-

Person p1 = new Person ( );
int m1 = p1.getMoney ( ); // statement1

The call to getMoney ( ) in statement1 will invoke the method defined in Person class.

Explanation :-

Non-private Non-static overridden method is executed from current object class.

Question 51 :-

statement2 :-

Person p2 = new Student ( );
int m2 = p2.getMoney ( ); //statement2

The call to getMoney ( ) in statement2 will invoke the method defined in Student class.

Explanation :-

Non-private non-static overridden method is executed from current object class.

 Use the following code fragments for the next 3 questions. Assume that: . student. Empileves, and Betired are all child classes of Peraen Student, Employee, an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site