checked exception issues in constructor
Demo 1:
package cons;
class P
{
P() throws Exception // checked exception
{
}
}
public class C extends P{
C() //error (unhandled exception type exception)
{
}
}
Demo 2:
package cons;
class P
{
P()
{
}
}
public class C extends P{
C()throws Exception // no error
{
}
}
Demo 3:
package cons;
import java.io.FileNotFoundException;
import java.io.IOException;
class P
{
P()throws IOException
{
}
}
public class C extends P{
C()throws FileNotFoundException // error
// unhandled exception type IOexception
{
}
}
Demo 4:
package cons;
import java.io.FileNotFoundException;
import java.io.IOException;
class P
{
P()throws FileNotFoundException
{
}
}
public class C extends P{
C()throws IOException //no error
{
}
}
Note : no errors in case of unchecked exceptions
0 comments:
Post a Comment