Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a static block in Java.
Java
class Example { static [1] { System.out.println("Static block executed"); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to print a message from a static block.
Java
class Demo { static { System.out.[1]("Hello from static block"); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the static block declaration.
Java
class Test { static [1]() { System.out.println("Static block"); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to create a static block that initializes a static variable.
Java
class Counter { static int count; static [1] { count [2] 100; } }
🎯 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 block that prints a message and initializes a static variable.
Java
class Init { static int number; static [1] { System.out.[2]("Initializing number"); number [3] 42; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
