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?
About Question com.enthuware.ets.scjp.v6.2.692 :
Moderators: Site Manager, fjwalraven
-
- Posts: 9
- Joined: Sat Feb 25, 2012 3:51 pm
- Contact:
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.692 :
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.
-
- Posts: 27
- Joined: Mon Sep 22, 2014 1:30 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.692 :
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.
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.
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.692 :
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.
thank you for your feedback!
Paul.
Who is online
Users browsing this forum: No registered users and 1 guest