Hi chandra,
I got it. I am not understanding the below mentioned code its from k&b.
import java.io.*;
class Master{
String doFileStuff() throws FileNotFoundException { return "a"; }
}
class Slave extends Master{
public static void main(String[] args){
String s=null;
try{ s=new Slave().doFileStuff();
}catch(Exception x) {
s= "b"; }
System.out.println(s);
}
//insert code here }
Which, inserted independently at // insert code here will compile and produce the output b?(choose all that apply)
A. String doFileStuff() { return "b" ; }
b. String doFileStuff() throws IOException { return "b" ;}
c. String doFileStuff(int x) throws FileNotFoundException {return "b"; }
d. String doFileStuff() throws FileNotFoundException {return "b"; }
e. String doFileStuff() throws NumberFormatException { return "b"; }
f. String doFileStuff() throws NumberFormatException, FileNotFoundException{ return "b"; }
Answers :
A,D,E,F. Its okay for an overriding method to throw the same exceptions,narrower exceptions or no exceptions.And it's okay for overriding method to throw any runtime exceptions
Can you explain me the options "e" and "f"?.