What will be the output?
public class Test{
static{
int a = 5;
}
public static void main(String args[]){
new Test().call();
}
void call(){
this.a++;
System.out.print(this.a);
}
}
public class Test{
static{
int a = 5;
}
public static void main(String args[]){
new Test().call();
}
void call(){
this.a++;
System.out.print(this.a);
}
}
A. Compile with error
B. Runtime Exception
C. 5
D. 6
E. 0
Answer: Option A
Join The Discussion
Comments ( 4 )
Related Questions on Declaration and Access Control
What is the default access modifier for class members in Java if no access modifier is specified?
A. public
B. protected
C. private
D. package-private
A. private
B. public
C. protected
D. package-private
What keyword is used to declare a constant in Java, which is implicitly final and static?
A. final
B. const
C. static
D. constant
A. protected
B. private
C. public
D. default
bcause scope of variable a is limited to static block. outside the static block variable a has not identification.
the variable 'a' in static block cannot able to access using this keyword
why compile time error
Why explain old