50.8k views
2 votes
Which code shows us creating an object of data type Scanner class and storing it with a variable named X ?

User PeaGon
by
7.0k points

1 Answer

5 votes

Final answer:

To create a Scanner object and store it in a variable named X, you need to import the Scanner class and instantiate the Scanner object.

Step-by-step explanation:

To create an object of the Scanner class in Java and store it in a variable named X, you need to import the Scanner class and then instantiate the Scanner object. Here is an example:

import java.util.Scanner;

public class MyClass {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
}
}

In this code snippet, we import the Scanner class from the java.util package and create an object named x of the Scanner class. This object is then stored in the variable named X.

User Abdul Hameed
by
7.8k points