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

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

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 »

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: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
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 »

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: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

soncrash
Posts: 8
Joined: Sat Aug 27, 2016 2:51 pm
Contact:

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

Post by soncrash »

I think it should not be consider as Very Easy question :)

Post Reply

Who is online

Users browsing this forum: No registered users and 53 guests