About Question enthuware.ocajp.i.v7.2.1372 :
Moderator: admin
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1372 :
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.
-
- Posts: 1
- Joined: Mon Jul 09, 2018 4:43 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1372 :
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?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1372 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 7
- Joined: Sat Sep 04, 2021 8:17 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1372 :
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."?
Why it caused ClassCastException ?
Also where can I find the "ExceptionClassSummary document in the "Study References" section."?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1372 :
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.
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.
Who is online
Users browsing this forum: No registered users and 47 guests