What will be the output after compiling and running following program code?
public class Test{
static int a;
public static void main(String[] args){
System.out.println("one");
call(1);
}
static void call(int a){
this.a=10;
System.out.println("two "+a);
}
}
public class Test{
static int a;
public static void main(String[] args){
System.out.println("one");
call(1);
}
static void call(int a){
this.a=10;
System.out.println("two "+a);
}
}
A. one two 1
B. one two 10
C. one two 0
D. Compile time error.
E. None of these
Answer: Option D
Solution(By Examveda Team)
Static members are common for all objects, where as ‘this’ refer to a particular object. so we cant use ‘this’ operator in the static methods.
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
Join The Discussion