• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem/ Failure in Practice Exams Book (java 6)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hope this / those problems doesn't occur.
It is question 29 of 2nd practice exam:


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


Answer:

B, C, D, and F are correct....



My answer was / would be C and F - because the method call "new Feynman().think();" doesn't declares or handles an exception. So B and D do cause an compile error. What do you think?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

moritz mueller wrote:
My answer was / would be C and F - because the method call "new Feynman().think();" doesn't declares or handles an exception. So B and D do cause an compile error. What do you think?


you are correct. probably author over looked in to that line ( but I think author intention is about checking overriding rule ).
 
reply
    Bookmark Topic Watch Topic
  • New Topic