What is the result of executing the following code? (Choose all that apply.)
import java.io.Console; import java.io.Writer; public class Main { public static void main(String[] args) throws Exception { String line;/*from w w w .j a v a 2s . c o m*/ Console c = System.console(); Writer w = c.writer(); if ((line = c.readLine()) != null) w.append(line); w.flush(); } }
B, D, E.
This is correct code for reading a line from the console and writing it back out to the console, making option B correct.
Options D and E are also correct.
If no console is available, a NullPointerException is thrown.
The append()
method throws an IOException.