This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

OCPJP 6 Practice exams, exam 2 q 29 error  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
author
Posts: 8995
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if main() throws exception?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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..
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!