Back to questions
JuniorTheoryCommon
What does the program print?
public class Main {
static int count;
static boolean ready;
public static void main(String[] args) {
System.out.print(count);
System.out.print(" ");
System.out.println(ready);
}
}0 false
- Expecting a compile error: only local variables must be assigned before a read; fields such as
countandreadyget default values. - Expecting
0 0, as in languages where false is a number: a Javabooleandefaults tofalseand prints asfalse.
- What default value does a
charfield get? - Why does a local variable get no default value?