Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, Java!" to the console.
Java
public class Main { public static void main(String[] args) { System.out.[1]("Hello, Java!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' will print text but not move to a new line.
Using 'write' or 'echo' are not valid methods here.
✗ Incorrect
The println method prints the text and moves to a new line.
2fill in blank
mediumComplete the code to declare an integer variable named 'age' with value 25.
Java
public class Main { public static void main(String[] args) { [1] age = 25; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integer' is not a Java keyword.
Using 'var' requires Java 10+, but 'int' is standard.
✗ Incorrect
In Java, int is the keyword to declare an integer variable.
3fill in blank
hardFix the error in the code to correctly create a Java class named 'Car'.
Java
public [1] Car { // class body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' or 'method' instead of 'class'.
Using 'interface' defines a different structure.
✗ Incorrect
Use the keyword class to define a class in Java.
4fill in blank
hardFill both blanks to declare a method named 'greet' that returns nothing and prints a message.
Java
public [1] greet() { System.out.[2]("Hello!"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as return type when method returns nothing.
Using 'print' instead of 'println' for new line.
✗ Incorrect
The method returns void (nothing) and uses println to print with a new line.
5fill in blank
hardFill all three blanks to declare a Java class 'Person' with a private String field 'name' and a constructor.
Java
public class Person { private [1] [2]; public Person([1] [2]) { this.[2] = [2]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' or 'age' instead of 'String' and 'name'.
Mismatching field and parameter names.
✗ Incorrect
The field is a String named name. The constructor uses the same type and name.