0
0
Javaprogramming~10 mins

What is Java - Interactive Quiz & Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aecho
Bprint
Cwrite
Dprintln
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.
2fill in blank
medium

Complete 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'
Aint
Binteger
Cvar
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integer' is not a Java keyword.
Using 'var' requires Java 10+, but 'int' is standard.
3fill in blank
hard

Fix 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'
Aclass
Bmethod
Cfunction
Dinterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' or 'method' instead of 'class'.
Using 'interface' defines a different structure.
4fill in blank
hard

Fill 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'
Avoid
Bprintln
Cprint
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as return type when method returns nothing.
Using 'print' instead of 'println' for new line.
5fill in blank
hard

Fill 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'
Aint
BString
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' or 'age' instead of 'String' and 'name'.
Mismatching field and parameter names.