Page 1 of 1

About Question enthuware.ocpjp.v8.2.1405 :

Posted: Fri Nov 04, 2016 7:28 am
by ja3ekja
Hej,
Question 49, Test 2, a) option said
File f = new File("x");   //1 will throw an exception at runtime if a file named "x" does not exist.
answer is:
You can always create a File object whether or not an actual file or directory by that name exists.
I have just create:
File f = new File("C:\\example.txt"); I do not have this on my disc and I receive exception.
Do you agree with me that it is mistake in this test?
The next option in test is also good but If I have to choose one I choose this.
Please help me.

Re: About Question enthuware.ocpjp.v8.2.1405 :

Posted: Fri Nov 04, 2016 8:32 am
by admin
No, the explanation is correct. Please post exact and complete code that you have tried and the output that you have received.

thank you,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1405 :

Posted: Mon Feb 20, 2017 2:07 pm
by runnerdave
Hi I copied and compiled the question and I receive the following compilation error:

TestClass.java:9: error: no suitable constructor found for PrintWriter(FileReader)
PrintWriter pw = new PrintWriter(new FileReader(f)); //4
^
constructor PrintWriter.PrintWriter(Writer) is not applicable
(argument mismatch; FileReader cannot be converted to Writer)
constructor PrintWriter.PrintWriter(OutputStream) is not applicable
(argument mismatch; FileReader cannot be converted to OutputStream)
constructor PrintWriter.PrintWriter(String) is not applicable
(argument mismatch; FileReader cannot be converted to String)
constructor PrintWriter.PrintWriter(File) is not applicable
(argument mismatch; FileReader cannot be converted to File)

Re: About Question enthuware.ocpjp.v8.2.1405 :

Posted: Mon Feb 20, 2017 9:43 pm
by admin
Yes, that is expected. That is why option 3 and 4 are incorrect. Explanation to option 3 says the same thing.
Paul.