AlgoMaster Logo

Packages & Modules - Quiz

Last Updated: January 3, 2026

1 min read

Packages & Modules Exercises

30 quizzes

1
Code Completion

Use a utility method without qualifying it with the class name after a static import

java
1
int maxValue = (a, b);

Click an option to fill the blank:

2
Code Completion

Reference a class from another package without using its fully qualified name

java
1
List<String> names = new <>();

Click an option to fill the blank:

3
Code Completion

Declare the package at the top of a source file to organize related classes

java
1
com.example.billing;

Click an option to fill the blank:

4
Multiple Choice

What is the main purpose of a Java package?

5
Multiple Choice

Where must the package declaration appear in a Java source file?

6
Multiple Choice

Which import allows you to use ArrayList without qualifying it?

7
Multiple Choice

What happens if two imported packages contain classes with the same simple name?

8
Multiple Choice

What does a static import allow you to do?

9
Multiple Choice

Which file defines a Java module's dependencies and exported packages?

10
Multiple Choice

Which keyword in module-info.java declares a dependency on another module?

11
Multiple Choice

What is true about packages in a Java module by default?

12
Multiple Choice

What does requires transitive com.example.utils; mean in module-info.java?

13
Multiple Choice

Which statement about import statements is correct?

14
Sequencing

Order the steps to create and use a class from a custom package in another class.

Drag and drop to reorder, or use the arrows.

15
Sequencing

Order the steps to define and consume a Java module that provides a math utility package.

Drag and drop to reorder, or use the arrows.

16
Output Prediction

What is the output of this code when using a class from another package via import?

1package com.example.app;
2
3import java.util.ArrayList;
4
5public class Main {
6    public static void main(String[] args) {
7        ArrayList<String> list = new ArrayList<>();
8        list.add("A");
9        list.add("B");
10        System.out.println(list.get(1));
11    }
12}
17
Output Prediction

What is the output when using a static import of Math methods?

1import static java.lang.Math.*;
2
3public class TestStaticImport {
4    public static void main(String[] args) {
5        int result = max(3, 7) - min(2, 5);
6        System.out.println(result);
7    }
8}
18
Output Prediction

What is the output when using two classes with the same name but different packages via fully qualified name?

1package com.example.use;
2
3class com_example_a_Message {
4    public static String get() { return "A"; }
5}
6
7class com_example_b_Message {
8    public static String get() { return "B"; }
9}
10
11public class Main {
12    public static void main(String[] args) {
13        String a = com_example_a_Message.get();
14        String b = com_example_b_Message.get();
15        System.out.println(a + b);
16    }
17}
19
Output Prediction

What is the output when a module exports a package containing a simple utility method?

1package com.example.util;
2
3public class GreetingUtil {
4    public static String build(String name) {
5        return "Hello, " + name;
6    }
7}
8
9class Main {
10    public static void main(String[] args) {
11        String msg = GreetingUtil.build("JPMS");
12        System.out.println(msg);
13    }
14}
20
Output Prediction

What is the output when using a constant via static import?

1package com.example.circle;
2
3import static java.lang.Math.PI;
4
5public class Area {
6    public static void main(String[] args) {
7        double area = PI * 1 * 1;
8        System.out.println((int)area);
9    }
10}
21
Bug Spotting

Find the bug related to the package declaration and imports.

Click on the line(s) that contain the bug.

java
1
public class ReportService {
2
    package com.example.reports;
3
 
4
    import java.util.List;
5
 
6
    public void generate(List<String> lines) {
7
        System.out.println("Report size: " + lines.size());
8
    }
9
}
22
Bug Spotting

Find the bug in this module descriptor and related class.

Click on the line(s) that contain the bug.

java
1
module com.example.app {
2
    require java.sql;
3
    exports com.example.app.service;
4
}
5
 
6
package com.example.app.service;
7
 
8
public class DbService {
9
    public String getDriverName() {
10
        return java.sql.Driver.class.getName();
11
    }
12
}
23
Matching

Match each Java keyword with its use in packages or modules.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

24
Matching

Match each module directive with its purpose.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Fill in the Blanks

Complete the code so that a class is correctly declared in a package and imported elsewhere.

java
1
com.example.services;
2
3
public class EmailService {
4
public void send(String to) {
5
System.out.println("Sending to " + to);
6
}
7
}
8
9
// In another file
10
com.example.services.EmailService;
11
12
class App {
13
public static void main(String[] args) {
14
EmailService service = new EmailService();
15
service.send("user@example.com");
16
}
17
}

Click an option to fill blank 1:

26
Fill in the Blanks

Complete the module descriptor to expose a package and depend on java.sql.

java
1
com.example.data {
2
java.sql;
3
com.example.data.repository;
4
}
5

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the static import usage so that methods and constants from Math are used without qualification.

java
1
static java.lang.Math.*;
2
3
public class Geometry {
4
public static double circleLength(double r) {
5
return 2 * * r;
6
}
7
}
8

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the imports to use List and LocalDate without qualifying them.

java
1
java.util.List;
2
java.time.LocalDate;
3
4
public class Booking {
5
private List<LocalDate> dates;
6
}
7

Click an option to fill blank 1:

29
Hotspot Selection

Click the line where a wildcard import is used for java.util classes.

Click on the line to select.

java
1
package com.example.demo;
2
 
3
import java.util.*;
4
import java.time.LocalDate;
5
 
6
public class Demo {
7
    public static void main(String[] args) {
8
        List<String> list = new ArrayList<>();
9
        System.out.println(list.isEmpty());
10
    }
11
}
30
Hotspot Selection

Click the line that declares the name of the module.

Click on the line to select.

java
1
module com.example.orders {
2
    requires java.logging;
3
    exports com.example.orders.api;
4
}
5