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

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

Moderator: admin

Post Reply
admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

The first one uses recursion. It will cause the stack to overflow if you run it for a large integer. For example, try calling it - factorial(Integer.MAX_VALUE)
If you like our products and services, please help us by posting your review here.

roberto1
Posts: 1
Joined: Mon Jul 09, 2018 4:43 am
Contact:

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

Post by roberto1 »

The questions asks about exceptions, but the right answer has an error in it? Those are different branches of the Throwable tree. Or do I see this the wrong as a non-native English speaker?

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

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

Post by admin »

The word "exception" (with a lower case e) implies all sorts of exceptions i.e. all instances of Throwable. The word "Exception" (with an upper case E) implies only Exception and its subclasses (including RuntimeExceptions). This is common terminology and is used by the exam as well.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

qazwsx922
Posts: 7
Joined: Sat Sep 04, 2021 8:17 pm
Contact:

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

Post by qazwsx922 »

I don't understand the third one. I thought it was "No exception will be thrown".
Why it caused ClassCastException ?

Also where can I find the "ExceptionClassSummary document in the "Study References" section."?

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

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

Post by admin »

The call to m1() returns an object of class java.lang.Object. Since Object does not satisfy the is-a relation with String (because an Object is not a String, although a String is an Object), if you try to cast it to String, the JVM will throw a ClassCastException.

It is like trying to force a Vehicle to be a Car. All Vehicles are not Cars even though all Cars are Vehicles.

You can read Exception class summary here.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests