• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gabriel Moreno
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  •  
    Paul Somnath
    Ranch Hand
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 284
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 284
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well that what am saying ans in book is incorrect. or a typo on the E option for line no.
     
    Vijitha Kumara
    Bartender
    Posts: 3913
    9
    Chrome Fedora Hibernate
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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.
     
    Paul Somnath
    Ranch Hand
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 284
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 8898
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Paul Wolberg
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bert,

    Is there a publicly accessible errata list for the book?
     
    Ankit Garg
    Sheriff
    Posts: 9521
    22
    Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 8898
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic