My Parent
class is :
import java.io.IOException;
public class Parent {
int x = 0;
public int getX() throws IOException{
if(x
Easy to remember
This code is valid
public class A {
protected String foo() throws Exception{
return "a";
}
class B extends A {
@Override
public String foo() throws IOException{
return "b";
}
}
}
Overrided foo method has public access, not protected and throws IOException that child of Exception
This code is not valid
public class A {
public String foo() throws IOException{
return "a";
}
class B extends A {
@Override
protected String foo() throws Exception{
return "b";
}
}
}
Overrided foo method has more restricted access modifier and throws Exception that NOT child of IOException
By the way you can override method from superclass and not throw ecxeptions at all
This code valid
public class A {
public String foo() throws IOException{
return "a";
}
class B extends A {
@Override
public String foo(){
return "b";
}
}
}