About Question enthuware.ocajp.i.v7.2.839 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Matheus

About Question enthuware.ocajp.i.v7.2.839 :

Post by Matheus »

Look at this question:

Code: Select all

How can you fix the following code to make it compile:
class Great {
    public void doStuff() throws FileNotFoundException{
    }    
}

class Amazing extends Great { 
  public void doStuff() throws IOException, IllegalArgumentException{
  }    
}

public class TestClass {
    public static void main(String[] args) throws IOException{
        Great g = new Amazing();
        g.doStuff();
    }
}
It asks for an option that allows the code to compile. The option Change doStuff in Amazing to throw only IllegalArgumentException., is correct in this point of view, but Change doStuff in Great to throw only IOException instead of FileNotFoundException. is also correct.

So this question is a little ambiguous.

Online
admin
Site Admin
Posts: 10402
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.839 :

Post by admin »

You are right. Both the options should be correct. This has now been fixed.

thank you for the feedback!

Guest

Re: About Question enthuware.ocajp.i.v7.2.839 :

Post by Guest »

I found another solution to the answer, which is different from the suggested answer.

Pick these options:
-Change doStuff in Amazing to throw only IOException.
-Change doStuff in Great to throw only IOException instead of FileNotFoundException.

I guess this will work.

Online
admin
Site Admin
Posts: 10402
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.839 :

Post by admin »

You are right but each option is independent of other options. A statement "Assume that changes suggested in a option are to be applied independent of other options." has now been added to avoid this confusion.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests