About Question enthuware.ocpjp.i.v11.2.3142 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
rowdyy
Posts: 3
Joined: Fri Jul 10, 2020 7:30 pm
Contact:

About Question enthuware.ocpjp.i.v11.2.3142 :

Post by rowdyy »

Test -1

83
-----------

Given: public static void main(String[] args){ try(FileInputStream fis = new FileInputStream("c:\\temp\\test.text")){ System.out.println(fis); } //line 1 }

Which of the following options can be inserted at //1 independent of each other to make the above code compile? Note that FileInputStream, try-with-resources, and multi-catch are NOT mentioned in the official exam objectives. However, we have seen questions in the exam that require knowledge on these topics. It is possible that these are questions are unscored i.e. their score doesn't count towards your final score. Since we have no way of knowing that, it is better to read up on these topics.

catch(IOException){ } ; This was specified as correct answer; but there is not identifier; like IOExceptio ioe;

This wont compile. Thats why i did not select this.


catch(IOException e){ } finally{  fis.close(); } -> This seems better option than the before one. But this option is wrong as per Enthuware.

admin
Site Admin
Posts: 9390
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3142 :

Post by admin »

You are right. It should have the parameter name. Fixed.

The last option invalid because the close() method on FileInputStream declares that it may throw IOException. So, the exception from the call to fis.close(); remains unhandled.
If you like our products and services, please help us by posting your review here.

kabanvau
Posts: 12
Joined: Thu Nov 21, 2019 5:48 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3142 :

Post by kabanvau »

The last option invalid because the close() method on FileInputStream declares that it may throw IOException. So, the exception from the call to fis.close(); remains unhandled.
I think it will not compile because the variable fis is not accessible from within the finally block. The same is with the first option.

admin
Site Admin
Posts: 9390
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3142 :

Post by admin »

You are right. Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests