Given:
import java.io.*;
public class SampleClass {
public static void main(String[] args) throws IOException {
try {
String dirName = args[0];
File dir = new File(dirName);
File.createTempFile("temp", "log", dir);
} catch (NullPointerException | IOException e) {
e = new IOException("Error while creating temp file");
throw e;
}
}
What is the result?
A.
Compilation fails.
B.
An IOException with the default message is thrown at runtime.
C.
An IOException with the message Error while creating temp file is thrown at runtime.
D.
A temporary file is created in the specified directory.
Explanation:
The multi-catch parameter e may not be assigned. The compilation will fail at line:
e = new IOException(“Error while creating temp file”);
Files.createTempFile(dir.toPath(), “Temp”, “.log”);
sorry, this is for nio