wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operators and Assignments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators and Assignments" Watch "Operators and Assignments" New topic
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: 2367
You can set any object reference equal to null.
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operators and Assignments