1Z0-805 無料問題集「Oracle Upgrade to Java SE 7 Programmer」
Given the code fragment:
private static void copyContents (File source, File target) {
try {inputStream fis = new FileInputStream(source);
outputStream fos = new FileOutputStream (target);
byte [] buf = new byte [8192]; int i;
while ((i = fis.read(buf)) != -1) {
fos.write (buf, 0, i);
}
//insert code fragment here. Line **
System.out.println ("Successfully copied");
}
Which code fragments, when inserted independently at line **, enable the code to compile?
private static void copyContents (File source, File target) {
try {inputStream fis = new FileInputStream(source);
outputStream fos = new FileOutputStream (target);
byte [] buf = new byte [8192]; int i;
while ((i = fis.read(buf)) != -1) {
fos.write (buf, 0, i);
}
//insert code fragment here. Line **
System.out.println ("Successfully copied");
}
Which code fragments, when inserted independently at line **, enable the code to compile?
正解:A、B、E
解答を投票する
解説: (JPNTest メンバーにのみ表示されます)
Given:
class Fibonacci extends RecursiveTask<Integer> {
final int n;
Fibonacci (int n) { this.n = n }
Integer compute () {
if (n <= 1)
return n;
Fibonacci f1 = new Fibonacci (n - 1);
f1.fork; // Line X
Fibonacci f2 = new Fibonacci (n - 2); // Line Y
return f2.compute() + f1.join;
}
}
Suppose that lines X and Y are transposed:
Fibonacci f2 = new Fibonacci (n - 2); // Line Y
f1.fork; // Line X
What is the likely result?
class Fibonacci extends RecursiveTask<Integer> {
final int n;
Fibonacci (int n) { this.n = n }
Integer compute () {
if (n <= 1)
return n;
Fibonacci f1 = new Fibonacci (n - 1);
f1.fork; // Line X
Fibonacci f2 = new Fibonacci (n - 2); // Line Y
return f2.compute() + f1.join;
}
}
Suppose that lines X and Y are transposed:
Fibonacci f2 = new Fibonacci (n - 2); // Line Y
f1.fork; // Line X
What is the likely result?
正解:C
解答を投票する
解説: (JPNTest メンバーにのみ表示されます)
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?
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?
正解:C
解答を投票する
解説: (JPNTest メンバーにのみ表示されます)