Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem/ Failure in Practice Exams Book (java 6)

 
moritz mueller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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 ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic