A

Admin • 832.27K Points
Coach

Q. What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}

  • (A) Compilation Fails
  • (B) Prints 0
  • (C) Prints 10
  • (D) Prints 10 D. Prints 7
  • Correct Answer - Option(A)
  • Views: 25
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

Choice A is the correct answer.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.