Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer variable with its default value.
Java
int number = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null for int variables causes errors.
Using quotes around 0 makes it a string, not an int.
✗ Incorrect
In Java, the default value for an int variable is 0.
2fill in blank
mediumComplete the code to declare a boolean variable with its default value.
Java
boolean isActive = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null for boolean causes errors.
Using quotes makes it a string, not a boolean.
✗ Incorrect
The default value for a boolean in Java is false.
3fill in blank
hardFix the error in the code by completing the declaration of a String variable with its default value.
Java
String name = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty quotes instead of null for default String value.
Assigning 0 or false to a String causes errors.
✗ Incorrect
In Java, the default value for a String (which is an object) is null.
4fill in blank
hardFill both blanks to declare a double and a char variable with their default values.
Java
double price = [1]; char grade = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 for char instead of '\u0000'.
Using null for primitive types causes errors.
✗ Incorrect
The default value for double is 0.0 and for char is the null character '\u0000'.
5fill in blank
hardFill all three blanks to declare variables of types long, float, and boolean with their default values.
Java
long count = [1]; float rate = [2]; boolean flag = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null for primitives causes errors.
Forgetting the 'f' suffix for float literals.
✗ Incorrect
Default values: long is 0, float is 0.0f, boolean is false.