GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 231 of 493    Print  
in overriding, the super class method throws I/O exception & in sub class that method throws arithmetic exception. what happens?

  
Total Answers and Comments: 3 Last Update: July 05, 2008     Asked by: sadashivarao 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
May 15, 2006 03:35:59   #1  
amit        

RE: in overriding, the super class method throws I/O e...

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.


 
Is this answer useful? Yes | No
May 22, 2006 03:02:05   #2  
abdul khalik        

RE: in overriding, the super class method throws I/O e...

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();
    }
}


 


 
Is this answer useful? Yes | No
July 05, 2008 06:46:34   #3  
R.Raj Member Since: April 2008   Contribution: 3    

RE: in overriding, the super class method throws I/O exception & in sub class that method throws arithmetic exception. what happens?
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  

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape