Given: 10. abstract class A { 11. abstract void al(); 12. void a2() { } 13. } 14. class B extends A { 15. void a1() { } 16. void a2() { } 17. } 18. class C extends B { void c1() { } } and: A x = new B(); C y = new C(); A z = new C(); Which four are valid examples of polymorphic method calls? (Choose four.)
-
x.a2();
-
z.a2();
-
z.c1();
-
z.a1();
-
y.c1();
-
x.a1();
A,B,D,F
Correct answer
Explanation
Polymorphic method calls work when the reference type has the method and the actual object's class overrides it. x.a2() and z.a2() are polymorphic - A declares a2(), B overrides it, and x/z reference B/C objects. x.a1() and z.a1() are polymorphic - A declares abstract a1(), B/C implement it. z.c1() and y.c1() are NOT polymorphic - reference type C has c1(), but reference z is type A (which doesn't have c1()), and y.c1() is just a normal call on C reference, not polymorphic.