153k views
1 vote
Which class is automatically imported by java?

group of answer choices
a.scanner
b.arraylist
c.file
d.integer

1 Answer

2 votes

Final answer:

The Scanner class is automatically imported by Java to read input from different sources. (option a)

Step-by-step explanation:

In Java, the 'Scanner' class is used for reading user input from the console. It is part of the 'java.util' package, and it needs to be imported explicitly using the 'import' statement to use its functionality in a Java program.

Here is an example of how to import the 'Scanner' class in Java:

import java.util.Scanner;

public class Example {

public static void main(String[] args) {

// Now you can use the Scanner class here

Scanner scanner = new Scanner(System.in);

// Rest of the code...

}

}

On the other hand, classes like' ArrayList', 'File', and Integer is part of 'java.util', 'java.io', and 'java.lang' packages respectively, but they are not automatically imported. If you want to use these classes, you need to import them explicitly in your Java code.

Therefore, the correct answer is a. Scanner.

The Scanner class is the only one among the provided options that need to be imported explicitly in Java, making it the correct choice for the question.

User AlphaGoku
by
8.2k points