Which of the following lines can be inserted at line 1 to make the program run?
//line 1 public class Main{ public static void main (String [] args){ PrintWriter pw = new PrintWriter(System.out); OutputStreamWriter osw = new OutputStreamWriter(System.out); pw.print("hello"); } }
Assume that PrintWriter and OutputStreamWriter are valid classes in java.io package.
Select 1 option
Correct Option is : B
A. import java.lang.*;
Although you can import java.lang package explicitly, it is not required
because this package is always imported by the compiler.
B. import java.io.*;
This will make all the classes of java.io package available.
C. import java.io.OutputStreamWriter;
This will only make OutputStreamwriter available.
PrintWriter will still be unavailable.
D. is wrong since include
is not valid keyword in Java.