Ask Question

Declare a Scanner reference variable fileInput, and assign it a newly created Scanner object that is associated with a file named "data1". (Do not concern yourself with any possible exceptions here- - assume they are handled elsewhere.)

+5
Answers (1)
  1. 30 December, 20:19
    0
    Scanner fileInput = new Scanner (new File ("data1"));

    Explanation:

    In JAVA Scanner class is used to get input from the user.

    In order to use this class an instance of this class is created also called an object.

    Here the fileInput is a reference variable which is also called instance variable used to access a Scanner object.

    new keyword is used here to create an instance or object of Scanner class.

    File is a class which works with files and directories. So new File ("data1") is used to create an object of File and data1 is passed to it because in order to create an instance of the class, a string, which can be a name of file or an object is passed.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Declare a Scanner reference variable fileInput, and assign it a newly created Scanner object that is associated with a file named "data1". ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers