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 Polymorphism2 { public static void main(String [] args) { A](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1706/9/4/5/53365bdebfdd615f1706945526660.jpg)
Select the one correct answer.
(a) The program will fail to compile.
(b) The program will compile, and print 0 when run.
(c) The program will compile, and print 1 when run.
(d) The program will compile, and print 2 when run.
(e) The program will compile, and print 3 when run.
public class Polymorphism2 { public static void main(String [] args) { A refl= new C (); B ref2 = (B) refl; System.out.println (ref2.g ()); } } class A { private int f() { return 0; } public int g() { return 3; } } class B extends A ( private int f() { return 1; } public int g() { return f(); } } class C extends B ( public int f() { return 2; } }
Step by Step Solution
3.49 Rating (152 Votes )
There are 3 Steps involved in it
c The program will print 1 when run The f methods in A and B are private and ... View full answer
Get step-by-step solutions from verified subject matter experts
