Sail E0 Webinar

MCQs

Total Questions : 31 | Page 4 of 4 pages
Question 31. 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());
}
}
  1.    Compilation Fails
  2.    Prints 0
  3.    Prints 10
  4.    Prints 7
  5.    None of these
 Discuss Question
Answer: Option A. -> Compilation Fails

Latest Videos

Latest Test Papers