• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two possible answers Q18 ch 4 page 282 from KB

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the code presents an statement that will give compilation error and another statement that might throw runtime error, but question says pick one answer, than what should be answered:
Here is the code:

The answer is compilation error at line 14. But I guess there is runtime error at line 13 as well.
[ July 15, 2003: Message edited by: Barkat Mardhani ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, why do you think there's a runtime error?
foo() is void, so there's a compiler error, since the second expression of the assertion must return a value.
let me know...
[ July 15, 2003: Message edited by: Andres Gonzalez ]
[ July 15, 2003: Message edited by: Andres Gonzalez ]
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barkat
First if there is only one possible answer select the one that says does not compile. If they want two answers select the other one. But it sounds absurd to ask for a runtime error along with a compilation error. How can you ever have a runtime error when you can not even compile the program.
Secondly which error are you talking about. I only encountered an AssertionError(after removing the compilation error).
For this question I would say that the answer should be compilation error alongwith any other suitable answer(if any). Runtime error at line 13 is wrong.
[ July 15, 2003: Message edited by: Anupam Sinha ]
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The AssertaionError is the runtime error I am talking about.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barkat
The answer is compilation error at line 14. But I guess there is runtime error at line 13 as well.

It is not possible for the code to even compile how can it have an AssertionError.
[ July 15, 2003: Message edited by: Anupam Sinha ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic