File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in exception" Watch "doubt in exception" New topic
Author

doubt in exception

V Gala
Ranch Hand

Joined: Aug 06, 2007
Posts: 113
Mindq
33. Consider the classes defined below:

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{}


Ans is a ,b ,e
why answer d is wrong
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
ok well!!i am not sure with the below answer but,,,
According to me what i can say is
the method



and in option d

it is throwing Arithematic Exception

d) int methodOne( int c, long d ) throws ArithmeticException{}


i hope it helps!!!
V Gala
Ranch Hand

Joined: Aug 06, 2007
Posts: 113
Hi

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.ArithmeticException

An overridding method can throw any unchecked exception
Arithmetic exception is unchecked
V Gala
Ranch Hand

Joined: Aug 06, 2007
Posts: 113
If you try to run with option d it will run
Try it
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Hi Gala,


This is the good question because,

On that method shows IO Exception not an Arithmetic Exception

FileNotFound Exception comes under the IOExcepion

but ArithmeticException comes under java.lang.ArithmeticException

I think , this is the reason

check and tell me your feedback.
V Gala
Ranch Hand

Joined: Aug 06, 2007
Posts: 113
when you are overriding method a method can throw any unchecked exception arithmeticexception is unchecked
So i think code will run properly with ArithmethicException

For Checked exception method can throws any subclass of IOException
Therefore it is can throw filenotfoundException
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Exactly Gala,

Now are you clear regarding this doubt , is it ?
V Gala
Ranch Hand

Joined: Aug 06, 2007
Posts: 113
thanks
Dave Walsh
Greenhorn

Joined: Jun 21, 2007
Posts: 24
Now I feel I must know the whole Exception tree hierarchy to pass the exam. Fantastic.
Jianghu Li
Greenhorn

Joined: Sep 01, 2007
Posts: 13
Originally posted by V Gala:
If you try to run with option d it will run
Try it


Yes, it run!
i am confused.....
Yuvaraj Nandakumar
Greenhorn

Joined: Aug 31, 2007
Posts: 2
Does all Sub-classes which inherit Runtime Exception belong to the category of unchecked exceptions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in exception