errors while performing a boxing conversion
Hi,
i don't understand why my answer was not considered correct.
Here is the question:
"Which of the following errors can be thrown by the runtime while performing a boxing conversion ?"
* NullPointerException
* OutOfMemoryError
original question http://www.irixtech.com/content/api-contents-ques-4 was included in API Contents: http://www.irixtech.com/java/scjp/mock-exam/api-contents
I answered NPE, as this kind of error(with small letter) or more precisely Exception can be produced with following lines:
Integer i = null;
int i2 = i;
If this answer is not considered to be correct then shouldn't the word "error" be written with capital letter, to indicate that an instance of Error is kept in mind not just a sign that something is not the way it should be?
Tnx in advance,
Ats
The example you provided is an unboxing conversion - Integer to int (Object to primitive) which cannot be applied to the said question.
A boxing conversion may lead to an OutOfMemoryError - http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5... - read the last part of this section. Most importantly, since a primitive type cannot have a null reference, the NullPointerException cannot occur as a result of a boxing conversion.
Try the following as member & local declarations -
int i;
Integer x = i;
As far as writing error as caps or small letter, the question becomes that of the English language vs Java vocabulary. "error" is not a proper noun so it needs to start with a small "e". If "error" were written with a caps "E" then we imply a proper noun & hence relate that to a Java class which gives away the answer. The word "error" in the question relates to an error condition & not necessarily an "Error" class.
Nevertheless, I've modified the question to read - "Which of the following errors/exceptions can be thrown by..."
HTH
Ashish Hareet