aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in K&B SCJP 6: topic Chapter5; question 15; option E Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in K&B SCJP 6: topic Chapter5; question 15; option E" Watch "Doubt in K&B SCJP 6: topic Chapter5; question 15; option E" New topic
Author

Doubt in K&B SCJP 6: topic Chapter5; question 15; option E

Gabriel Moreno
Greenhorn

Joined: Aug 14, 2008
Posts: 5
A question 15 of chapter 5 self test, option E says:

Where it says: "...adding a try/catch block around line 6 will cause compilation to fail"

Well... line 6 is the class closing bracket. So writing a try catch around it will not make any sense to the compiler at all. Compilation would fail! Yet the correct answer according to the book is D not E
Paul Somnath
Ranch Hand

Joined: May 19, 2008
Posts: 177
Many of us dont have SCJP 6 by K&B.
So this is a request to all ranchers that please post the actual question, as many of us may not have the book along with us while viewing the post.


Preparing for SCJP 6.0
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Here's the code



given these four code fragments
I. public static void main(String[] args){
II. public static void main(String[] args)throws Exception{
III. public static void main(String[] args)throws IOException{
IV. public static void main(String[] args)throws RuntimeException{

Which of following are true
A. All four will compile & execute without exception
B. All four will compile and execute and throws an exception
C. Some but not all, will compile and execute without exception
D. Some, but not all,will compile and execute and throw an exception
E. When considering fragments II, III and IV, of those that will compile, adding a try/catch block around line 6 will cause compilation to fail.

I think that it sould be line 4 instead of line 6....


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Narendra my bro, the question is about what line should be inserted at the commented line.

//insert code here

this thing is not written for fun ...you have to put the line of codes(individually) at the commented line. The lines to put are marked as I,II,III and IV........
Pradeep Balasubramanian
Ranch Hand

Joined: Jun 16, 2008
Posts: 75
Here's the code

code:

1.public class Frisbee{
2. //insert code here
3. int x = 0;
4. System.out.println(7/x);
5. }
6.}



given these four code fragments
I. public static void main(String[] args){
II. public static void main(String[] args)throws Exception{
III. public static void main(String[] args)throws IOException{
IV. public static void main(String[] args)throws RuntimeException{

Which of following are true
A. All four will compile & execute without exception
B. All four will compile and execute and throws an exception
C. Some but not all, will compile and execute without exception
D. Some, but not all,will compile and execute and throw an exception
E. When considering fragments II, III and IV, of those that will compile, adding a try/catch block around line 6 will cause compilation to fail.


  • All Options (I,II,III and IV) will work. but,for the option III to work you need to import the io package.


  • Regards,<br />Pradeep Balasubramanian<br /> <br />You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul. <br /> <br />- Swami Vivekananda
    Paul Somnath
    Ranch Hand

    Joined: May 19, 2008
    Posts: 177
    If the question is the same as posted here, then adding try/catch block at line 6 would certainly cause a compiler error. And according to answer, if only Option D is to be the only correct option, option E has to be incorrect, and for it to be incorrect, the line number should be 4.
    Other suggestions are welcome.
    Paul Somnath
    Ranch Hand

    Joined: May 19, 2008
    Posts: 177
    Originally posted by Pradeep Balasubramanian:

  • All Options (I,II,III and IV) will work. but,for the option III to work you need to import the io package.


  • Yes that is also an issue, but I guess the import statement is intentionally not coded so that option D becomes correct.
    Nice tricky question.
    Pranav Bhatt
    Ranch Hand

    Joined: Mar 20, 2006
    Posts: 284
    Well i think both D and E should be true. As adding try/catch outside the main method will surely throw compilation error.
    Paul Somnath
    Ranch Hand

    Joined: May 19, 2008
    Posts: 177
    Originally posted by Pranav Bhatt:
    Well i think both D and E should be true. As adding try/catch outside the main method will surely throw compilation error.

    That is what the poster said. But if you read the post properly he says that the answer in the book is option D. And the question is whether the options are incorrect or the answer is incorrect?
    Pranav Bhatt
    Ranch Hand

    Joined: Mar 20, 2006
    Posts: 284
    Well that what am saying ans in book is incorrect. or a typo on the E option for line no.
    Vijitha Kumara
    Bartender

    Joined: Mar 24, 2008
    Posts: 3859


    Pranav Bhatt
    ---------------------------------------------------------------------------
    Well i think both D and E should be true. As adding try/catch outside the main method will surely throw compilation error.


    E is wrong because it is saying
    When considering fragments II, III and IV, of those that will compile

    here adding III option won't compile without import statement or full package name of IOException. Hope this is clear.


    SCJP 5 | SCWCD 5
    [How to ask questions] [Twitter]
    Paul Somnath
    Ranch Hand

    Joined: May 19, 2008
    Posts: 177
    When considering fragments II, III and IV, of those that will compile


    Its says of those that will compile, and so only of II and IV from the code fragments. Fragment III dosent even compile so it is not taken into consideration in this opotion. So the line number should be changed for the answer to be D.
    Pranav Bhatt
    Ranch Hand

    Joined: Mar 20, 2006
    Posts: 284
    Vijitha,
    When considering fragments II, III and IV, of those that will compile
    -> leaves us with option II,IV only. Now both of them will give compile error if you add try/catch at line 6. So E should be correct here.

    Or might be the english is tricky. They meant to say that only on these two we will get compilation error and not on the I/O exception for try/catch block. In this case E would be false

    [ September 02, 2008: Message edited by: Pranav Bhatt ]
    [ September 02, 2008: Message edited by: Pranav Bhatt ]
    Paul Somnath
    Ranch Hand

    Joined: May 19, 2008
    Posts: 177
    I dont think that exam-makers would make the grammar confusing. Its a technical question.
    When considering fragments II, III and IV, of those that will compile [this narrows down the options to II and IV], adding a try/catch block around line 6 will cause compilation to fail[Of II and IV, adding try/catch at line 6 would definately make compile time errors].

    So either the statement in Option E should be changed to line 4
    or
    The answer to the question should be marked as D and E
    [ September 02, 2008: Message edited by: Somnath Paul ]
    Bert Bates
    author
    Sheriff

    Joined: Oct 14, 2002
    Posts: 8883
        
        5
    Hi Guys,

    Early in this thread Ankit got it right. There is an error in the question, you have my apologies, it should say line 4, not line 6.

    I have entered this error into my list and when we have a few more we'll publish a new errata list.

    Sorry for the confusion!

    Bert


    Spot false dilemmas now, ask me how!
    (If you're not on the edge, you're taking up too much room.)
    Paul Wolberg
    Greenhorn

    Joined: Sep 03, 2008
    Posts: 1
    Bert,

    Is there a publicly accessible errata list for the book?
    Ankit Garg
    Sheriff

    Joined: Aug 03, 2008
    Posts: 9321
        
      17

    Hey Bert I also found one question confusing. I think there is an error in the question. Here's the link to that question
    [ September 03, 2008: Message edited by: Ankit Garg ]
    Bert Bates
    author
    Sheriff

    Joined: Oct 14, 2002
    Posts: 8883
        
        5
    Hi Ankit,

    It would be a huge help if you went back to the other thread and reposted the question you're talking about. When you repost it, please include everything, exactly as it is in the book!

    Thanks,

    Bert
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Doubt in K&B SCJP 6: topic Chapter5; question 15; option E