About Question enthuware.ocajp.i.v7.2.1305 :

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

Moderator: admin

Post Reply
olimpicco
Posts: 1
Joined: Wed Apr 10, 2013 1:51 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by olimpicco »

I have a question to this "The main method of a program can declare that it throws checked exceptions."
I found that if both subclass and superclass had a method main I can't throw checked exceptions from main in subclass (when superclass doesn't throw anything). Why this happens?

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

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by admin »

olimpicco, although this is not exactly a case of overriding (because static methods are not overridden), the same rule about exception applies to static methods. The subclass's method cannot throw any new exception unless it is a subclass of the exception thrown by the super class's method.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

vchhang
Posts: 36
Joined: Tue May 06, 2014 8:30 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by vchhang »

What am I missing here? The question states to select two true statement.

Option#4 states "A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class."

The explanation of why this is wrong is: "Note that it cannot throw the instances of any superclasses of the exception."

Here is my thought. Please help me understand what I am missing.

If a method declares that it throws a certain exception, then inside the method it should be able throw any subset of that exception class. Throwing a subset of the exception is the same as saying throwing any subset of the exception class. If I understand this correctly, it is wrong because it states that it may throw INSTANCES of any subclass of that exception class. Therefore if the term "instances" is removed, this option would be correct. Is my understanding correct here? If so, I believe the explanation should read as follows:

"Note that it cannot throw the instances of any SUBclasses of the exception."

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

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by admin »

This option is correct. Please see attached. (Repaint issue).
Attachments
2.1305.png
2.1305.png (41.36 KiB) Viewed 5399 times
If you like our products and services, please help us by posting your review here.

Rinkesh
Posts: 35
Joined: Sat Nov 25, 2017 4:13 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by Rinkesh »

Finally block has 3 exceptions in which It won't be executed:-

1.System.exit(1);
2.When return statement is used in finally block
3.When an exception arises in the code written in the finally block.
Am I right?

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

Re: About Question enthuware.ocajp.i.v7.2.1305 :

Post by admin »

Well, in case 2 and 3, finally is getting executed even if not fully.
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 69 guests