What is the result, if the file salesreport.dat does not exist?

Given the code fragment:

What is the result, if the file salesreport.dat does not exist?

Given the code fragment:

What is the result, if the file salesreport.dat does not exist?

A.
Compilation fails only at line 6

B.
Compilation fails only at line 13

C.
Compilation fails at line 6 and 13

D.
Class java.io.IOException

E.
Class java.io.FileNotFoundException

Explanation:
Compilation works fine.
There will be a runtime error at line 6 (as the file salesreport.dat) does not exist.
This will be caught as an IOException at line 17.



Leave a Reply 10

Your email address will not be published. Required fields are marked *


Martin

Martin

It’s like that:
public static void main(String[] args) {
try(BufferedReader br = new BufferedReader(null)){
br = new BufferedReader(null);
} catch (IOException e) {
e.printStackTrace();
}
}

And the result is: B)
because all resources in the try() are automatically final. So another assignment failed

Ray

Ray

After run coding, it shows
class java.io.FileNotFoundException

So the answer should be E

Tim

Tim

Did you really tried to code and compile the code? I tried and it cannot be compiled. So the answer should be B.

Charlie

Charlie

B. The resource br of a try-with-resources statement cannot be assigned.

Serg

Serg

B. The resource br of a try-with-resources statement cannot be assigned

Luiz

Luiz

B. The resource br of a try-with-resources statement cannot be assigned

Rudi

Rudi

The correct Answer is B.

Tested in Eclipse :

Compile Fails at line 13 : The resource br of a try-with-resources statement cannot be assigned

gelete

gelete

B

Compilation fails at line 13:
The resource br of a try-with-resources statement cannot be assigned