Page 1 of 1

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

Posted: Thu Dec 13, 2012 10:00 pm
by ETS User
The question asks to select 2 answers but the solution only has one choice.

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

Posted: Fri Dec 14, 2012 6:50 am
by admin
I see that options 1 and 4 are marked as correct.
q2.839.gif
q2.839.gif (47.79 KiB) Viewed 9919 times

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

Posted: Thu Mar 21, 2013 6:11 am
by Guest
I have a different question from the above for this reference number. It asks me to select one answer and the code is:

Code: Select all

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

The question asks "How can you fix the following code to make it compile?" and the supposed solution is "Change doStuff in Great to throw only IOException instead of FileNotFoundException".

As far as I can see, this only makes work if java.io.IOException is imported before the code. It will not compile if nothing is imported, like in the actual code given, and will compile without problems if java.io.* is imported.

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

Posted: Thu Mar 21, 2013 6:38 am
by admin
You are right, this statement has now been added to the code. For the purpose of the exam, though, please keep in mind that you may have have to make certain assumptions based on given options. For example, in this case, the question doesn't tell you that the code exists in TestClass.java file. If the file name is something else, it will not compile. But "Remove public from TestClass" is not an option. Therefore, you may assume that the file name is correct. Similarly, import java.io.* is not an option, so you can assume that appropriate imports are present.

HTH,
Paul.

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

Posted: Tue Dec 22, 2015 3:02 pm
by iamslrr
What impact does the throw in the TestClass main method have on the question? It doesn't seem like it will impact the exception handling of other methods at all. Is it there as an attempt to confuse the issue?

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

Posted: Tue Dec 22, 2015 3:15 pm
by admin
I am not sure I understand your question. The code will not compile without the throws clause. You should try it out.
-Paul.

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

Posted: Tue Dec 22, 2015 5:22 pm
by iamslrr
When I answered this question I did not think the the exception throw by the main method has an impact on the exceptions thrown by the Amazing and Great classes. I will try it out as you have instructed. Thanks.

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

Posted: Tue May 26, 2020 1:15 pm
by swarna pakeer
explanation says "The overriding method in the subclass is free to not throw any checked exception at all even if the overridden method throws a checked exception. No exception is a valid subset of exceptions thrown by the overridden method".
this sentence is little confusing as it says subclass overriding method cannot throw any checked exception at all when it can throw subclasses of Exception class of overridden method. and i know it cannot throw new or broader checked exceptions .am i missing something?

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

Posted: Tue May 26, 2020 1:22 pm
by admin
>>this sentence is little confusing as it says subclass overriding method cannot throw any checked exception at all
No, that is not what that sentence says! Please read carefully.

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

Posted: Mon Apr 12, 2021 1:33 am
by alfredo.zuloaga
If you do
Change doStuff in Amazing to throw only IOException.
also works
lass Great {
public void doStuff() throws IOException {}
}

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

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

Posted: Mon Apr 12, 2021 1:46 am
by admin
No, it doesn't work. Check your code for class Great. It is not the same as what is given in the problem statement.

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

Posted: Wed Jun 16, 2021 5:12 am
by af1981
Good Morning,

this question has got 2 right answers. The added one is:

1. Change doStuff in Amazing to throw only IOException;
2 Change doStuff in Great to throw only IOException instead of FileNotFoundException.

Making the code below to compile too. Thanks for your support. Have a good day and a good work.

import java.io.*;
class Great {
public void doStuff() throws IOException{
}
}

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

public class TestClass {
public static void main(String[] args) throws IOException{
Great g = new Amazing();
g.doStuff();
}
}

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

Posted: Wed Jun 16, 2021 7:52 am
by admin
Not sure I understand what you are saying. Are you saying the answers given in the question are incorrect?

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

Posted: Sun Jul 17, 2022 3:38 am
by klaashielke
I came here for the same reason as user "af1981". Also to me it seems that multiple answer combinations are correct for this question. Answer C: "change doStuff() in Amazing to only throw IOException" and answer D "change doStuff() in Great to only throw IOException" will result in the super class, sub class, and main method all only throwing an IOException, which compiles.

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

Posted: Sun Jul 17, 2022 4:56 am
by admin
The problem statement explicitly says, "Assume that changes suggested in a option are to be applied independently of changes suggested in other options."
So you have to consider each option individually and not in combination of any other option.