| Author |
Operators and Assignments
|
John Mathew
Greenhorn
Joined: Apr 17, 2007
Posts: 13
|
|
class Green { public static void main (String args[]) { int[] i = null; // 1 Cloneable c = i; // 2 i = (int [])c; // 3 }} What is the result of attempting to compile and run the program? a. Compile-time error at line 1. b. Run-time error at line 1. c. Compile-time error at line 2. d. Run-time error at line 2. e. Compile-time error at line 3. f. Run-time error at line 3. g. None of the above the answer is none None of the above.Can anyone elaborate on this?How is it possible to assign null reference to an integer array.
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Hi Rahul, Welcome to JavaRanch; Is this SCJP question? Cloneable is not on the exam objective list; ------- cmbhatt
|
cmbhatt
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
You can set any object reference equal to null.
|
 |
Joshua Smith
Ranch Hand
Joined: Aug 22, 2005
Posts: 192
|
|
Rahul- The fact that the question uses Comparable is not all that important. The key thing to understand about it is that arrays of primitives are objects and can be manipulated as such. That means that you can cast them, assign them to Object references, call toString(), hashCode() and equals() on them, etc. While some of the code below looks weird, it's totally valid: Hope that helps, Joshua Smith
|
Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
|
 |
 |
|
|
subject: Operators and Assignments
|
|
|