Write a statement that declares a PrintWriter reference variable named output and initializes it to a reference to a newly created PrintWriter object associated with a file named "output.txt".

Respuesta :

Answer:

PrintWriter variable = new PrintWriter("output.txt");

Explanation:

There are two ways of declaring a reference variable in programming.

One way is

Reference Variable-name = new Reference ("some texts here");

While the other is

Reference Variable-name;

Variable-name = new Reference ("some texts here");

Both ways are valid ways of reference variable declaration.

In the question above, the reference is PrintWriter, it points to output.txt and the question says "write a single statement";

Hence, we make use of

PrintWriter variable = new PrintWriter("output.txt");

A reference variable is declared to be of a specific type and that type can never be changed.