File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer?

 
Stoian Azarov
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is from the BB && KS Practice Exams book

29. Given that:
Exception is the superclass of IOException, and
IOException is the superclass of FileNotFoundException, and

Which of the following methods, inserted independently at line 11, compiles? (Choose all
that apply.)
A. void think() throws Exception { }
B. void think() throws FileNotFoundException { }
C. public void think() { }
D. protected void think() throws IOException { }
E. private void think() throws IOException { }
F. void think() { int x = 7/0; }

Answer (for Objective 1.4):
B, C, D, and F are correct. It’s legal for overridden methods to have less restrictive
access modifiers, to have fewer or narrower checked exceptions, and to have unchecked
exceptions. (Note: Of course, F would throw an exception at runtime.)

A is incorrect because Exception is broader. E is incorrect because private is more
restrictive.

________________________________________
I think there is something wrong with the answer
B does not compile because FileNotFoundException is not caught in the main method
D does not compile because IOException is not caught in the main method

Can someone confirm my supposition, or I am missing something?
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right. For B & D, in order for the code to compile, the public static void main(String[] args) method must either claim to throw the checked exception or handle the checked exception.
 
matej spac
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, you are right, I post same question few months ago, Bert Bates confirm an error in question.
Read this:

http://www.coderanch.com/t/535259/java-programmer-SCJP/certification/OCP-exams-Overriding
 
Stoian Azarov
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,

Strange that I couldn't find that thread.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic