TrainBeaser for iPhone
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Programmer Certification (SCJP)
 
RSS feed
 
New topic
Author

A possible wrong answer in ExamLab?

Jennifer Zhen
Greenhorn

Joined: May 24, 2009
Messages: 12


Hello, I found in the Practice exam 1, the 41th question:



the answer is the result of the program would be throwing (runtime) NumberFormatException. But I figured since A is the superclass, when you call B with A ref, the compliler got check if the checked exception is handled. And it's true that when I tested in a real IDE, a complier error happened.
Narendhiran Nagarajan
Ranch Hand

Joined: Jun 17, 2009
Messages: 30

NumberFormatException and InterruptedException are Unchecked (Runtime) Exceptions.
When you override a method, you can declare any Unchecked exception.But the checked exceptions cannot be new or broader than the overridden method.

Naren
-------------------
SCJP - 90%
SCWCD - 98%
Sridhar Gudipalli
Ranch Hand

Joined: Nov 02, 2005
Messages: 65

I have not looked into the actual question. But, if ab.blast() would surround with try/catch, then the answer (runtime exception) would be correct.
Either it is typo in question or missed the "compile time error" option in solution(s).

try {
ab.blast();
}
catch (InterruptedException e) {
e.printStackTrace();
}

Thank you,
Sridhar Gudipalli
Preparing SCJP (310-065) | SCJP FAQ | SCJP Mock Tests | Java Spec
Henry Wong
author
Bartender

Joined: Sep 28, 2004
Messages: 10022

Narendhiran Nagarajan wrote:NumberFormatException and InterruptedException are Unchecked (Runtime) Exceptions.


InterrruptedException is a checked exception -- and Jennifer is correct in that the compiler should complain.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Devaka Cooray
Bartender

Joined: Jul 29, 2008
Messages: 1371

Jennifer

Nice subject line. But the code you posted here is not exactly from ExamLab. It seems you edited the code. In the ExamLab question, there is a "throws" declaration for the main method, so there are no error at compile time. In ExamLab, there is a "Copy Program" button, so you can easily copy and paste the code here.

This is the exact code:


Author of ExamLab - the free mock exam kit for SCJP
[Home Page] . [Twitter Profile] . [JavaRanch FAQ] . [How to Ask a Question]
Narendhiran Nagarajan
Ranch Hand

Joined: Jun 17, 2009
Messages: 30

Sorry for giving wrong info.

Eventhough Interrupted Exception is a checked exception, it will not create a problem.
As I said early
"When you override a method, you can declare any Unchecked exception.But the checked exceptions cannot be new or broader than the overridden method. "
I would like to add that-
"Unless its needed, the overriding method doesnt have to declare all the Checked Exceptions, what the overridden method have."

So, b.blast() doesnt have to declare the InterruptedException or its subtype.

Naren
-------------------
SCJP - 90%
SCWCD - 98%
Jennifer Zhen
Greenhorn

Joined: May 24, 2009
Messages: 12


Hi Devaka,

I'm sorry for the subject line, but I was puzzled at the first place, that was true. Yes, you were right, I could have copied and pasted the code, but on my ThinkPad T40, which I am not sure why the resolution is not right when running ExamLab so I had to installed it on a separate slower machine, which I don't have IDEs.

Yes, you are right. If the throw clause is added to the main function, then it is fine.

Thanks for the clarifying.


Devaka Cooray wrote:Jennifer

Nice subject line. But the code you posted here is not exactly from ExamLab. It seems you edited the code. In the ExamLab question, there is a "throws" declaration for the main method, so there are no error at compile time. In ExamLab, there is a "Copy Program" button, so you can easily copy and paste the code here.

This is the exact code:

Devaka Cooray
Bartender

Joined: Jul 29, 2008
Messages: 1371

Jennifer Zhen wrote:I'm sorry for the subject line,


No I meant that this subject line is really good , because it makes me to read this topic. So, if there are any errors, I can figure them out and fix them.

Author of ExamLab - the free mock exam kit for SCJP
[Home Page] . [Twitter Profile] . [JavaRanch FAQ] . [How to Ask a Question]
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Programmer Certification (SCJP)
 
RSS feed
 
New topic
IntelliJ open source

.