Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Ques from k&b

 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

String doFileStuff() throws IOException ( return "b"; }

I was not able to understand, why the above statement(in Bold) is giving compilation err.
please explain this....Thank U
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that the '(' before the return is a typo, it should be '{'.

What does the error message mean to you? Reading the error message carefully will give you a very good idea of what is wrong.
[ December 26, 2006: Message edited by: Barry Gaunt ]
 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mr.Barry Gaunt. I have just copy pasted from the Book.



The problem is IOException is above the FileNotFoundException in the hierarchy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic