Sail E0 Webinar
Question
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());
}
}
Options:
A .  Compilation Fails
B .  Prints 0
C .  Prints 10
D .  Prints 7
E .  None of these
Answer: Option A

Submit Your Solution Below and Earn Points !

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers