What is the output for the below code?
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
A. 0 false 0
B. 0 true 0
C. 0 0 0
D. Compile error - static variable must be initialized before use.
E. None of these
Answer: Option A
Solution(By Examveda Team)
Global and static variable need not be initialized before use. Default value of global and static int variable is zero. Default value of boolean variable is false. Remember local variable must be initialized before use.
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Join The Discussion