my dog learned polymorphism*
The moose likes Mock Exam Errata and the fly likes MindQ question 33 - throwing ArithmeticException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "MindQ question 33 - throwing ArithmeticException" Watch "MindQ question 33 - throwing ArithmeticException" New topic
Author

MindQ question 33 - throwing ArithmeticException

Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
Hi Again

Which of the following are legal method declarations to add to the class Sub? Assume that each method is
the only one being added.
a) public static void main( String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
I marked correct answers as a) b) d) e) but d) is not given as correct answer.
I my opinion there is no restricition on AritmaticException() when overridding in sub classess.
Am I missing something
ALkesh
Jane Rozen
Ranch Hand

Joined: Feb 12, 2000
Posts: 53
You're right.
There have been discussions about it at this forum, one message was posted by Tony,called "Good(IMO) Practice Question" - search for it .(I don't know how to include links in replies).
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
The answers given is wrong. There is no restriction for an overriding method in throwing a RuntimeException/Error or any subclass of RuntimeException/Error . The compiler doesn't care about it as long as the other overriding rules are followed .
And your answers are all correct.
regds
maha anna
Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
hi Maha anna,
So can you please put the information regarding this question in the Mock Exam Errata Forum because I found this question in MindQ mack exam
ALkesh
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I'll move it now. Also, note that actually A is the only one really correct because all the others are declared to return int, long, or float - but none have return statements. So it's a pretty crappy question all around.


"I'm not back." - Bill Harding, Twister
Chetan Valia
Greenhorn

Joined: Jul 07, 2000
Posts: 1
It goes like this ...
The overriding method must not throw checked exceptions of classes that are not possible for the original method (overridden). There is however no restrictions on numbers of Exceptions.
Rob Whelan
Ranch Hand

Joined: Oct 18, 2000
Posts: 33
Originally posted by Chetan Valia:
It goes like this ...
The overriding method must not throw checked exceptions of classes that are not possible for the original method (overridden). There is however no restrictions on numbers of Exceptions.

Right, and ArithmeticException is not a checked exception, so that code (if it returned the proper data type, as mentioned above...) will compile correctly.
Robin Luo
Greenhorn

Joined: Nov 15, 2000
Posts: 3
Option D is wrong, and should not be chosen.
Because option D is an overriding method, therefore have to follow this rule:
"It (Java) will not allow the overriding subclass to be declared as throwing a more general exception or EXCEPTION FROM ANOTHER HIERARCHY." (from <<Java 2 Exam Cram>>, Bill Brogden, page 131)
The exceptions (in the super class and in the subclass) are in different branch of the Exception hierarchy.
Cheers,
Robin
 
Don't get me started about those stupid light bulbs.
 
subject: MindQ question 33 - throwing ArithmeticException