Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

re; MindQ test question

 
art mudick
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a question from MindQ test
import java.io.*;
class Super
{
int methodOne( int a, long b ) throws IOException
{ // code that performs some calculations
}
float methodTwo( char a, int b )
{ // code that performs other calculations
}
}
public class Sub extends Super
{
}
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 chose answer a,b,d and e. Could someone tell me if it right.
 
Lucy C
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer e is not valid, as an overriding method like this can't throw any checked exceptions that aren't thrown by the method it overrides - and FileNotFoundException is a checked exception.
ArithmeticException is a runtime exception, so d is valid.
 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e is valid becoz FileNotFoundException is a subclass of IOException .U can have the same Exception as in Overridden method or its subclass
 
Lucy C
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right - I didn't read the code properly. Better not do that in the exam...
 
Chuck Lan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so a is okay, b is okay because it's method overloading. c is not okay because the overriding method has a different return type. d is okay because ArithmeticException is a runtime exception. e is okay because FileNotFoundException is a subclass of IOException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic