What will be the outcome of compiling and running the given code? class A int b=10; private A() this.b=7; int f() return b; class B is an extension of class A int b; public class Test public static void main (String[] args) A a = new B(); System.out.println(a.f());
A. Prints 7
B. Prints 0
C.The compilation fails.
D. Produces 10 prints
Answer:C
What will be the outcome of compiling and running the given code? class A int b=10; private A() this.b=7; int f() return b; class B is an extension of class A int b; public class Test public static void main (String[] args) A a = new B(); System.out.println(a.f());
A. Prints 7 B. Prints 0 C.The compilation fails. D. Produces 10 prints
Explanation: The code does not compile because the function Object() { [native code] } of class A is marked as private. This causes a problem when the subclass function Object() { [native code] } makes an implicit super() call to the parent class function Object() { [native code] } when B is instantiated. Because the code does not compile, all of the other options are incorrect. If A's function Object() { [native code] } had not been private, the outcome would have been 7.