Originally posted by Tony Sam:
import java.io.*;
class Base{
private void amethod(int iBase) throws [b]IOException{
System.out.println("Base.amethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
try{
o.amethod(iBase);}
catch(Exception e){}
}
public void amethod(int iOver) throws Exception{
System.out.println("Over.amethod");
}
}//end here
This program compiles OK,but i wonder whether this is a overridden method. if yes,this must be compile error! A litter confused, Please tell me more about overridden and overloaded method!
Thanx in advance![/B]
U guessed right Tony! amethod(int)
being private in base class can't be overriden. Private methods are private to class only so they are not inheritaed. Therefore,
0.amethod() actually calls Over class's amethod().
If u change base class method as...
public void amethod(int iBase) throws IOException{}
then the version in over class becomes an overriden method. so compiler raises error as...
Over.java:15: amethod(int) in Over cannot override amethod(int) in Base; overridden method does not throw java.lang.Exception
public void amethod(int iOver) throws Exception{
This is because the overriden method can throw anly subset of exceptions thrown by base class method.
Hopr this helps!!

Rashmi
[This message has been edited by Rashmi Gunjotikar (edited December 02, 2001).]