Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. (10 pts) Given the following Java code class C public int foo (C p) t return

ID: 3600275 • Letter: 3

Question

3. (10 pts) Given the following Java code class C public int foo (C p) t return 1; h class D extends CI public int foo(C p) t return 2; h public int foo (D p) return 3; h cp=new C(); Ca=new D(); 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

Explanation / Answer

i =1

Explanation:- In this case the foo method in class C is called

j = 2

Explanation:- In this case the reference to the object created by new D(); is stored in q. And the first method in class D which accepts Objects of Class C is called

k =3

Explanation:- In this case the reference to the object created by new D(); is stored in q. And the second method in class D which accepts Objects of Class D is called

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote