About Question com.enthuware.ets.scjp.v6.2.72 :

Moderator: admin

Post Reply
devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.72 :

Post by devlam » Sun Feb 09, 2014 5:02 am

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.

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

Re: About Question com.enthuware.ets.scjp.v6.2.72 :

Post by admin » Sun Feb 09, 2014 5:09 am

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.

devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.72 :

Post by devlam » Sun Feb 09, 2014 7:02 am

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.
This code is compiling fine:
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();
}
}

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

Re: About Question com.enthuware.ets.scjp.v6.2.72 :

Post by admin » Sun Feb 09, 2014 7:44 am

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.
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 9 guests