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?
About Question enthuware.ocajp.i.v7.2.1305 :
Moderator: admin
-
- Posts: 1
- Joined: Wed Apr 10, 2013 1:51 pm
- Contact:
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1305 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 36
- Joined: Tue May 06, 2014 8:30 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1305 :
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."
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."
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1305 :
This option is correct. Please see attached. (Repaint issue).
- Attachments
-
- 2.1305.png (41.36 KiB) Viewed 5399 times
If you like our products and services, please help us by posting your review here.
-
- Posts: 35
- Joined: Sat Nov 25, 2017 4:13 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1305 :
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?
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?
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1305 :
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.
Who is online
Users browsing this forum: No registered users and 69 guests