Question: 3. (10 pts) Given the following Java code: class C public int foo (C p) return 1; class D extends C public int foo (C

3. (10 pts) Given the following Java code: class C public int foo (C p) return 1; class D extends C public int foo (C p) return 2; ) public int foo(D p)f return 3; C pnew CO C qnew DO D rnew DO int i-p.foo(r) int j = q. foo (q) ; int k-q.foo (r) (Remember that in Java every object is accessed through a pointer and that methods are virtual by default.) Which methods get called in the three calls, i.e., what are the values of i, j, and k? Explain how the method selection works to result in these values
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
