Java Output Prediction Easy +10 XP
Default int Value
What is the default value of an int field in a class?
JavaRead-only
class Example {
int x;
}
Example e = new Example();
System.out.println(e.x);What is the output?
Show answer and explanation
Answer: 0
Instance fields in Java are automatically initialized: int defaults to 0, boolean to false, objects to null.
Hint: Java initializes numeric fields to zero.
What this challenge tests
Output Prediction in Java: defaults, fields.