Which of the following lines can be inserted at line 1 to make the program run?
//line 1
public class TestClass{
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
A. import java.lang.*;
B. import java.io.*;
C. import java.io.OutputStreamWriter;
D. include java.io.*;
E. include java.lang.System;
Given the following contents of two java source files:
package util.log4j;
public class Logger {
public void log(String msg){
System.out.println(msg);
}
}
and
package util;
public class TestClass {
public static void main(String[] args) throws Exception {
Logger logger = new Logger();
logger.log("hello");
}
}
What changes, when made independently, will enable the code to compile and run?
Select 2 options
A. Replace Logger logger = new Logger(); with:
log4j.Logger logger = new log4j.Logger();
B. Replace package util.log4j; with
package util;
C. Replace Logger logger = new Logger(); with:
util.log4j.Logger logger = new util.log4j.Logger();
D. Remove package util.log4j; from Logger.
E. Add import log4j; to TestClass.
If you want to solve the questions together with the experts and understand the concepts better, please contact us using the contact form or WhatsApp numbers. Selected people get to do that without any additional charges.