File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators and Assignments" Watch "Operators and Assignments" New topic

Operators and Assignments

John Mathew

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: 1710
Hi Rahul,

Welcome to JavaRanch;

Is this SCJP question?

Cloneable is not on the exam objective list;


Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
You can set any object reference equal to null.
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193

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-
I agree. Here's the link:
subject: Operators and Assignments
It's not a secret anymore!