About Question enthuware.ocajp.i.v7.2.1223 :

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

Moderator: admin

Post Reply
lecadre24
Posts: 1
Joined: Sun Apr 06, 2014 11:23 am
Contact:

About Question enthuware.ocajp.i.v7.2.1223 :

Post by lecadre24 »

It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException...
If I understand the explanation declaring RuntimeExceptions is optional and not a must.
So why is "It must ..." correct?

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

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by admin »

This option is not marked as correct.
If you like our products and services, please help us by posting your review here.

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by pfilaretov »

"It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException" still marked as correct one.

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by pfilaretov »

pfilaretov wrote:"It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException" still marked as correct one.
sorry, that's not true. Just looked at checkbox, not at correct answers

GurmeetGulati
Posts: 2
Joined: Thu Oct 16, 2014 7:35 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by GurmeetGulati »

Can you please elaborate on your explanation and answers.

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

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by admin »

Sure, if you can tell which part do you have a problem understanding, I can explain further.
If you like our products and services, please help us by posting your review here.

rafaparche
Posts: 5
Joined: Tue Apr 14, 2015 9:32 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by rafaparche »

Hi, I don't understand why It is ok if it declares just throws ArrayIndexOutOfBoundsException and It does not need to declare any throws clause are valid answers?

Thanks!

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

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by admin »

Since ArrayIndexOutOfBoundsException is a RuntimeException, it can be specified in any throws clause without any issue. Also, since it is a RuntimeException, there is no need to specify it in any throws clause either.
I suggest you to write some code to try out a few scenarios involving this.
HTH,
Paul
If you like our products and services, please help us by posting your review here.

Chandu
Posts: 7
Joined: Thu Mar 30, 2017 7:15 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by Chandu »

Consider the following hierarchy of Exception classes :

java.lang.RuntimeException
+-------- IndexOutOfBoundsException
+---------ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException

Which of the following statements are correct for a method that can throw ArrayIndexOutOfBounds as well as StringIndexOutOfBounds Exceptions but does not have try catch blocks to catch the same?


"The method calling this method will either have to catch these 2 exceptions or declare them in its throws clause"
This option is not valid in this question is because it is case of Runtime exception, but it would have been correct if it was case of Compile time exception right?

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

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by admin »

Yes, it would have been correct if they were checked exceptions. The method could also either catch a super class of these two exceptions (such as Exception or Throwable) or declare in its throws clause.
If you like our products and services, please help us by posting your review here.

girishankaran
Posts: 10
Joined: Wed Aug 08, 2012 5:00 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by girishankaran »

Hi All,
Why the following is wrong?
It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
and how this is right?
It is ok if it declares just throws ArrayIndexOutOfBoundsException
Thanks

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

Re: About Question enthuware.ocajp.i.v7.2.1223 :

Post by admin »

Already explained above. It is invalid because of "must".
Since both are RuntimeExceptions, there is no need to specify them in any throws clause.
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 216 guests