Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a static variable named count.
Java
public class Counter { public static [1] count = 0; }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to access the static variable count from the class Counter.
Java
int currentCount = Counter.[1];🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the code to correctly increment the static variable count.
Java
public class Counter { public static int count = 0; public void increment() { [1]++; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to create a static method that returns the static variable count.
Java
public class Counter { private static int count = 0; public static [1] getCount() { return [2]; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to create a class with a static variable, a constructor that increments it, and a static method to get its value.
Java
public class [1] { private static int count = 0; public [2]() { [3]++; } public static int getCount() { return count; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
