100k views
3 votes
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".

User IpsRich
by
8.2k points

1 Answer

3 votes

Answer:

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

Step-by-step 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.

User Dupinder Singh
by
8.2k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.