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.
About Question enthuware.ocpjp.v8.2.1405 :
Moderator: admin
-
- Posts: 2
- Joined: Fri Nov 04, 2016 5:27 am
- Contact:
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1405 :
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.
thank you,
Paul.
-
- Posts: 12
- Joined: Mon Jan 30, 2017 2:58 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1405 :
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)
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)
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1405 :
Yes, that is expected. That is why option 3 and 4 are incorrect. Explanation to option 3 says the same thing.
Paul.
Paul.
Who is online
Users browsing this forum: Bing [Bot] and 16 guests