0
0
Javaprogramming~5 mins

Default values in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'\u0000' (null character)
B' ' (space character)
C'0' (zero character)
DNo default value
Which of these variables will NOT have a default value in Java?
ALocal variables
BStatic variables
CInstance variables
DClass variables
What is the default value of a double variable in Java?
A0
B0.0
Cnull
DNaN
What default value does a String variable have in Java?
A"null" (string literal)
B"" (empty string)
Cnull
DNo default value
Why is it important to initialize local variables in Java?
ABecause they have random default values
BBecause they are final
CBecause they are static
DBecause they do not have default values
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.