File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes OCPJP 6 Practice exams, exam 2 q 29 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "OCPJP 6 Practice exams, exam 2 q 29 error" Watch "OCPJP 6 Practice exams, exam 2 q 29 error" New topic
Author

OCPJP 6 Practice exams, exam 2 q 29 error

Kristian Lund
Greenhorn

Joined: Oct 27, 2011
Posts: 1
29. Given that:

Exception is the superclass of IOException, and
IOException is the superclass of FileNotFoundException, and
3. import java.io.*;
4. class Physicist {
5. void think() throws IOException { }
6. }
7. public class Feynman extends Physicist {
8. public static void main(String[] args) {
9. new Feynman().think();
10. }
11. // insert method here
12. }

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; }


The book gives B,C,D and F as answers. B and D wont compile because the call from the main method does not handle the exception.

So the right answer is C and F.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
How about if main() throws exception?


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
samir vasani
Ranch Hand

Joined: Nov 24, 2010
Posts: 59
Kristian Lund wrote:
29. Given that:

Exception is the superclass of IOException, and
IOException is the superclass of FileNotFoundException, and
3. import java.io.*;
4. class Physicist {
5. void think() throws IOException { }
6. }
7. public class Feynman extends Physicist {
8. public static void main(String[] args) {
9. new Feynman().think();
10. }
11. // insert method here
12. }

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; }


The book gives B,C,D and F as answers. B and D wont compile because the call from the main method does not handle the exception.

So the right answer is C and F.



Hi ,,

Here it is not provided that main() throws IOException..
So if it is included then the answer is BCDF .
It is not necessary that every time they correct.

If possible please mention the source..
John Wintermute
Greenhorn

Joined: Nov 01, 2011
Posts: 14
Bert Bates wrote:How about if main() throws exception?


Hi there,

Are you saying we can assume that, when the individual lines are added, that main() might change to accommodate the change? It makes questions hard to answer as it's a little ambiguous.

I hope there's not too many like that on the exam! But I suppose that, if we're told how many answers to select, then B and D are the only possible choices other than C and F, so we'd have to choose them.

Cheers, john


ocjp december 2011 -
may peace prevail on earth
 
Don't get me started about those stupid light bulbs.
 
subject: OCPJP 6 Practice exams, exam 2 q 29 error
 
Similar Threads
BB && KS Practice Exams - Practice Exam 2, question 29 - wrong answer?
Overridden method and exceptions
OCP JP Practice Exam 2 #29
OCP exams - Overriding question
Overriding and exceptions declaration