wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer?" Watch "BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer?" New topic
Author

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

Stoian Azarov
Ranch Hand

Joined: Jun 01, 2011
Posts: 113
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

Joined: May 13, 2002
Posts: 180
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

Joined: Apr 21, 2011
Posts: 28
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


|OCPJP 6|
Stoian Azarov
Ranch Hand

Joined: Jun 01, 2011
Posts: 113
Thanks guys,

Strange that I couldn't find that thread.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer?