• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

https://coderanch.com/t/535259/java-programmer-SCJP/certification/OCP-exams-Overriding
 
Stoian Azarov
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys,

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