In test10 question com.enthuware.ets.scjp.v6.2.72.
When I click on discuss I end up in the discussion of com.enthuware.ets.scjp.v6.2.720.
I wanted to put the following discussion on .72
Additional information for explanation:
When the overriden method throws a runtime exception in stead of the exception, the try/catch of throw is not necessary.
About Question com.enthuware.ets.scjp.v6.2.72 :
Moderator: admin
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.72 :
That is not correct. Whether try/catch or throw is necessary depends on the type of the reference that is used to make the call, not on the actual object. This is already explained in the given explanation.
If you like our products and services, please help us by posting your review here.
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.72 :
This code is compiling fine:admin wrote:That is not correct. Whether try/catch or throw is necessary depends on the type of the reference that is used to make the call, not on the actual object. This is already explained in the given explanation.
package com.familievlaming.ocpjp.proefexamens;
public class OverridingMethodThrowsRuntimeException {
void methodThrowsRuntimeException() throws NullPointerException {
}
void methodThrowsRuntimeException2() throws NullPointerException {
}
}
class SubOverridingMethodThrowsRuntimeException extends OverridingMethodThrowsRuntimeException{
void methodThrowsRuntimeException() {
}
void methodThrowsRuntimeException2() throws NullPointerException {
}
public static void main(String[] args) {
OverridingMethodThrowsRuntimeException o = new SubOverridingMethodThrowsRuntimeException();
o.methodThrowsRuntimeException();
o.methodThrowsRuntimeException2();
}
}
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.72 :
I am not sure what you are trying to prove. The code you've written does not the reflect the situation we are talking about. Your base class method doesn't have a throws clause with a checked exception.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Sat Aug 27, 2016 2:51 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.72 :
I think it should not be consider as Very Easy question
Who is online
Users browsing this forum: No registered users and 53 guests