67 Method Overriding Rules for Exception in Java

Code:

import java.io.*;

class A
{
void m1() throws IOException
{

}
}

class B extends A
{

/* We Can write Same Class Exception
void m1() throws IOException
{

}
*/


/* We Can write Sub Class Exception
void m1() throws FileNotFoundException
{

}
*/

/* But we cannot write Super Class Exception
void m1() throws Exception
{

}
*/


/* We Cannot write
void m1() throws IllegalAccessException
{

}

*/

}

class Test
{
public static void main( String args[] )
{
System.out.println(" Coding Atharva ");
}
}


Output:


Previous
Next Post »