Exception doubt
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Read the following piece of code carefully.
An attempt to compile the above class definition ...
Will cause a compiler error - non-abstract classes cannot be extended to abstract classes.
Will cause a compiler error - a constructor must be provided which may or may not throw an IOException
will cause a compiler error - a constructor must be provided which must throw an IOException or one of its super types.-answer
will not cause any compiler error. The class definition is perfectly legal.
IOException's sub type or super type. I think the extended class can throw the original type or sub type of exception from it's super class.
An attempt to compile the above class definition ...
Will cause a compiler error - non-abstract classes cannot be extended to abstract classes.
Will cause a compiler error - a constructor must be provided which may or may not throw an IOException
will cause a compiler error - a constructor must be provided which must throw an IOException or one of its super types.-answer
will not cause any compiler error. The class definition is perfectly legal.
IOException's sub type or super type. I think the extended class can throw the original type or sub type of exception from it's super class.
SCJP-1.5<br />SCWCD-1.4
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi
The subclass constructor must throw IOException or supertype
consider these two method and try to link with constructor
class A
{
void met1() throws IOException
{
throw new IOException();
}
}
class B
{
void met2() throws FileNotFoundException
{
met1();
}
}
now met2() will not be able to handle IOException
therefore it should be
void met2() throws Exception(IOException)
{
met1();
}
The subclass constructor must throw IOException or supertype
consider these two method and try to link with constructor
class A
{
void met1() throws IOException
{
throw new IOException();
}
}
class B
{
void met2() throws FileNotFoundException
{
met1();
}
}
now met2() will not be able to handle IOException
therefore it should be
void met2() throws Exception(IOException)
{
met1();
}
dolly shah
Ranch Hand
Posts: 383
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
But you should write (IOException) instead of (Exception)
SCJP-1.5<br />SCWCD-1.4
V Gala
Ranch Hand
Posts: 113
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
both exception and ioexception can catch IOException
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
doll, its like saying...
and there it blows up!
and there it blows up!
SCJP Tiger Hunter 91%.
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Dolly,
if you say "IOException's sub type" then just ask a question,
How would a sub-type handle a super type exception..
A simple as that..
Also it is clearly mentioned in K&B book regarding the same
Regards,
Gitesh
if you say "IOException's sub type" then just ask a question,
How would a sub-type handle a super type exception..
A simple as that..
Also it is clearly mentioned in K&B book regarding the same
Regards,
Gitesh
| A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









