File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "arrays" Watch "arrays" New topic
Author

arrays

pree sree
Ranch Hand

Joined: Jul 27, 2002
Posts: 34
this ?is from http://www.parikosh.com/
Q#10. True or false
public class Arrays1 {
public static void main(String[] args) {
int[] a1 = { 1, 2, 3, 4, 5 };
int a2[];
float f1[] = new float[5];
a2 = a1;
for(int i = 0; i < a2.length; i++)
f1[i] = (float)a2[i]++;
for(int i = 0; i < f1.length; i++)
System.out.println(
"a1[" + i + "] = " + f1[i]);
}
}
a. Program will give compiler error, because incompatable array type
b. output will be 0.0 0.0 0.0 0.0 0.0
c. output will be null null null null null
d. program will give complier error, because possible use of array before its
initialization.
e. will give 1.0 2.0 3.0 4.0 5.0
the answer given is e.
how does a2=a1 compile both being arrays?thanks in advance.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
a2 is, after the assignment, an alias to the same object pointed by a1.
Being arrays of the same primitive type keeps the compiler happy.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: arrays
 
Similar Threads
Array
Array increment
Multidimensional Arrays
doubts in 4 questions
multi-dimension array question - dan's exam