• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MindQ question 33 - throwing ArithmeticException

 
Nilesh Parikh
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chetan Valia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic