In overriding, the super class method throws I/O exception & in sub class that method throws arithmetic exception. what happens?

Questions by sadashivarao   answers by sadashivarao

Showing Answers 1 - 5 of 5 Answers

amit

  • May 15th, 2006
 

while overriding, methos in subclass can not throw any new checked exception. it can only decalre exception already declared in the super class or its subclasses.

since Airthmetic exception is an unchecked exception it can be declared without any error.

  Was this answer useful?  Yes

abdul khalik

  • May 22nd, 2006
 

program will work fine Example:-

/*
 * OverSuper.java
 *
 *Created on May 22, 2006, 12:11 PM
 *Concept: overriden method can throw diffrent exceptions
 *its method will be overriden in Overriding.
 */

package concepts;
import java.io.*;
/**
 *
 * @author Abdul
 */
public class OverSuper {
   
    protected void myFunction() throws IOException{
   
 System.out.println("Method in super class throwing IOExcption");
    }
   
}

####################################################

/*
 * Overriding.java
 *
 * Created on May 22, 2006, 12:10 PM
 *
 * this class overrides a method of super class and try to throw differnt type of excption
 *
 */

package concepts;
import java.io.*;
/**
 *
 * @author Abdul
 */
public class Overriding extends OverSuper{
   
  
    public Overriding() {
    }
   
    protected void myFunction() throws ArithmeticException{
   
 System.out.println("this is ovverriden in sub class throws arithmetic exception");
    }
    public static void main(String[] arg){
   
 Overriding ov=new Overriding();
 ov.myFunction();
    }
}


 

  Was this answer useful?  Yes

R.Raj

  • Jul 5th, 2008
 

Hi Amit,

Actually in overriding there are some rules need to be follow.
Overriding means the method with same signature as the super class,
and signature means the name of the method,number of arguments etc.
If super class is throwing one exception and sub class is throwing another,then it doesn't comes under Overriding.

Thanks  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions