Page 1 of 1

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

Posted: Sun Feb 09, 2014 5:02 am
by devlam
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.

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

Posted: Sun Feb 09, 2014 5:09 am
by admin
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.

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

Posted: Sun Feb 09, 2014 7:02 am
by devlam
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();
}
}

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

Posted: Sun Feb 09, 2014 7:44 am
by admin
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.

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

Posted: Sat Apr 01, 2023 3:23 pm
by soncrash
I think it should not be consider as Very Easy question :)

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

Posted: Fri May 31, 2024 11:12 pm
by gadsgadsx
I agree with the guy who commented above. This is definitely not "very easy". Very hard to spot the problem in compilation here, actually!