Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

A possible wrong answer in ExamLab?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 6888
1312
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Narendhiran Nagarajan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jennifer Zhen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 6888
1312
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic