File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in exception

 
V Gala
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to run with option d it will run
Try it
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly Gala,

Now are you clear regarding this doubt , is it ?
 
V Gala
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Dave Walsh
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I feel I must know the whole Exception tree hierarchy to pass the exam. Fantastic.
 
Jianghu Li
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic