0
0
Javaprogramming~15 mins

Static methods in Java - Interactive Code Practice

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

Complete the code to declare a static method named greet.

Java
public class Hello {
    public static void [1]() {
        System.out.println("Hello, world!");
    }
}
🎯 Drag options to blanks, or click blank then click option
Agreet
Brun
Cstart
Dmain
Attempts:
3 left
2fill in blank
medium

Complete the code to call the static method greet from the main method.

Java
public class Hello {
    public static void greet() {
        System.out.println("Hello, world!");
    }

    public static void main(String[] args) {
        [1]();
    }
}
🎯 Drag options to blanks, or click blank then click option
AHello.greet
Bnew Hello().greet
Cgreet
Dthis.greet
Attempts:
3 left
3fill in blank
hard

Fix the error in calling the static method greet from another class named App.

Java
public class Hello {
    public static void greet() {
        System.out.println("Hello from Hello class!");
    }
}

public class App {
    public static void main(String[] args) {
        [1]();
    }
}
🎯 Drag options to blanks, or click blank then click option
AHello.greet
Bgreet
CApp.greet
Dnew Hello().greet
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a static method square that returns the square of an integer.

Java
public class MathUtils {
    public static int [1](int num) {
        return num [2] num;
    }
}
🎯 Drag options to blanks, or click blank then click option
Asquare
B*
C+
Dmultiply
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a static method isEven that returns true if a number is even, otherwise false.

Java
public class NumberUtils {
    public static boolean [1](int n) {
        return n [2] 2 [3] 0;
    }
}
🎯 Drag options to blanks, or click blank then click option
AisEven
B%
C==
D!=
Attempts:
3 left