Given Following Code, why is it not allowed for MyMethod() to declare IOException in MyExp2 class( question 9 from
http://www.javacaps.com/scjp_mockexams1.html )???
Overriding a method that doesnt throw Exception wont have overriden method which does throw Exception?
Do Overriden methods have some scope rule for throwing exceptions as in they can only throw exceptions that are already thrown in the overridden method of subclass??
<CODE>
import java.io.*;
class MyExp {
void MyMethod() throws IOException, EOFException {
//............//
}
}
class MyExp1 extends MyExp {
void MyMethod() {
//..........//
}
}
public class MyExp2 extends MyExp1 {
void MyMethod() throws IOException {
//.........//
}
}
</CODE>
Can an overloaded method throw an exception?
like:
<CODE>
class Shit
{
protected void m_DoShit()
{}
protected void m_DoShit(int i)
throws MyException
{}/*assume MyException is derived from IOException*/
}
class BullShit extends Shit
{
public void m_DoShit(int i)
throws IOException
{}
}
</CODE>
------------------