Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a static variable.
Java
public class Example { static int [1] = 10; }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to call a static method from the class.
Java
public class Calculator { public static int add(int a, int b) { return a + b; } public static void main(String[] args) { int result = Calculator.[1](5, 3); System.out.println(result); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in accessing a non-static variable from a static method.
Java
public class Counter { int count = 0; public static void main(String[] args) { Counter c = new Counter(); System.out.println(c.[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.
Java
public class Data { static int value = 100; public static [1] getValue() { return [2]; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill both blanks to create a class with a static variable, a non-static variable, and a method that prints both.
Java
public class Info { static String [1] = "StaticVar"; String [2] = "InstanceVar"; public void printInfo() { System.out.println([1] + " and " + [2]); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
