Review Questions |
6.25 |
What will be the result of attempting to compile and run the following program?
public class Polymorphism { public static void main(String[] args) { A ref1 = new C(); B ref2 = (B) ref1; System.out.println(ref2.f()); } } class A { int f() { return 0; } } class B extends A { int f() { return 1; } } class C extends B { int f() { return 2; } } Select the one correct answer.
|
Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.