Consider the following code: interface I1 { public void f(): } class A implement
ID: 3884045 • Letter: C
Question
Consider the following code: interface I1 { public void f(): } class A implements I1 { public void f() { //implementation } public static void g(){ //implementation } } class B extends A { public void f() { //implementation } public static void g(){ //implementation } } Suppose I1 i1 = new B(): I1 i2 = new A(): A a1 = new A(): A a2 = new B(): A b1 = (A) new B(): Without writing any code, explain in words the effect of each of the following method calls. Just say things like "will call f method implemented in A" etc. b1.f(): b1.g(): i1.f(): a1.g(): i2.f(): a2.g();Explanation / Answer
Answer:
b1.f() will call f method implemented in B
b1.g(); will call g method implemented in A
i1.f(); will call f method implemented in B
a1.g(); will call g method implemented in A
i2.f(); will call f method implemented in A
a2.g(); will call g method implemented in A
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.