Recall & Review
beginner
What are default values in Java?
Default values are the initial values assigned automatically to variables when they are declared but not explicitly initialized.
Click to reveal answer
beginner
What is the default value of an
int variable in Java?The default value of an
int variable is 0.Click to reveal answer
beginner
What default value does a
boolean variable have in Java?A
boolean variable defaults to false if not initialized.Click to reveal answer
beginner
What is the default value of a reference type variable (like an object) in Java?
Reference type variables default to
null if not initialized.Click to reveal answer
intermediate
Do local variables in Java have default values?
No, local variables do not have default values and must be initialized before use.
Click to reveal answer
What is the default value of a
char variable in Java?✗ Incorrect
The default value of a
char variable is the null character '\u0000'.Which of these variables will NOT have a default value in Java?
✗ Incorrect
Local variables must be initialized before use; they do not get default values.
What is the default value of a
double variable in Java?✗ Incorrect
The default value of a
double variable is 0.0.What default value does a
String variable have in Java?✗ Incorrect
String is a reference type, so its default value is null.
Why is it important to initialize local variables in Java?
✗ Incorrect
Local variables do not have default values and must be initialized before use to avoid errors.
Explain what default values are in Java and give examples for at least three data types.
Think about what happens if you declare a variable but don't assign a value.
You got /2 concepts.
Why do local variables in Java require explicit initialization before use?
Consider the difference between local and instance variables.
You got /2 concepts.