Question: What will be the result of compiling and running the following program? Select the one correct answer. (a) The program will fail to compile. (b)
What will be the result of compiling and running the following program?
![public class Polymorphism ( public static void main (String[] args) { A](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1706/9/4/5/45965bdebb3d65361706945457886.jpg)
Select the one correct answer.
(a) The program will fail to compile.
(b) The program will compile, but will throw a ClassCastException at runtime.
(c) The program will compile, and print 0 when run.
(d) The program will compile, and print 1 when run.
(e) The program will compile, and print 2 when run.
public class Polymorphism ( public static void main (String[] args) { A refl= new C(); B ref2 = (B) refl; System.out.println (ref2.f()); } } class A class B extends A { int f() { class C extends B { int f() { { int f() { return 0; } } return 1; } } return 2; } }
Step by Step Solution
3.30 Rating (144 Votes )
There are 3 Steps involved in it
e The program will print 2 when Systemoutprintlnref2f is executed The o... View full answer
Get step-by-step solutions from verified subject matter experts
