Ask Question
21 March, 08:03

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"));

+1
Answers (1)
  1. 21 March, 08:30
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers