About Question com.enthuware.ets.scjp.v6.2.692 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
MC20147
Posts: 9
Joined: Sat Feb 25, 2012 3:51 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.692 :

Post by MC20147 »

I'm confused in how option 2 could be correct but option 5 is not given that the question asks "which will exit without any output and exceptions if no arguments are given). Running either with no args (or with args for that matter) gives the same result.

I understand that you won't ever get a NullPointer for a String[] but I think option 5 still meets what the questions is asking.

Am I interpreting this wrong?

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

Re: About Question com.enthuware.ets.scjp.v6.2.692 :

Post by admin »

Option 5 is not correct because if you run it without any arguments, it will throw ArrayIndexOutOfBoundsException, which is not being caught. Therefore, it does not meet what the question is asking.

piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.692 :

Post by piotrkmiotczyk »

Ditto what MC20147 said.

Question:
'Which code fragments will print the last argument given on the command line to the standard output, and exit without any output and exceptions if no arguments are given?'

- I find it hard to agree that point 2 will 'exit without exceptions'. Program does not run its course normally, it throws ArrayIndexOutOfBoundsException.

Comment to point 5:
'if you run it without any arguments, it will throw ArrayIndexOutOfBoundsException, which will not be be caught by catch(NullPointerException ) and therefore it will end up throwing ArrayIndexOutOfBoundsException on the command line'.

- Aha! If exercise is about an exception which prints to command line (is not suppressed, like in 2), then to my mind it was not stated clearly in the question.

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

Re: About Question com.enthuware.ets.scjp.v6.2.692 :

Post by admin »

The problem statement has been updated to make it clear that it is talking from the command line perspective.

thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests