Ask Question

Which of the following declares a valid PrintWriter object that represents an output file named myOutput. txt? PrintWriter out = new File ("myOutput. txt"); PrintWriter out = new Scanner ("myOutput. txt"); PrintWriter out = new PrintWriter ("myOutput. txt"); PrintWriter out = new PrintWriter (new File ("myOutput. txt"));

+2
Answers (1)
  1. 11 April, 04:13
    0
    PrintWriter out = new PrintWriter (new File ("myOutput. txt"));

    Explanation:

    PrintWriter object is used to create an abstraction to a File for writing purpose.

    PrintWriter constructor with File object input takes one of the two forms:

    PrintWriter (File) PrintWriter (File, String).

    Among the given options, option 4 corresponds to PrintWriter object creation using the first version of PrintWriter constructor.

    So the valid option that declares a PrintWriter object for an output file 'myOutput. txt' is:

    PrintWriter out = new PrintWriter (new File ("myOutput. txt"));
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Which of the following declares a valid PrintWriter object that represents an output file named myOutput. txt? PrintWriter out = new File ...” 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