Ask Question
20 October, 21:47

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. 21 October, 01:05
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers