Get your CodeRanch badge!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's Question:clone() 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 "Dan Watch "Dan New topic
Author

Dan's Question:clone()

tonghua li
Greenhorn

Joined: Jun 07, 2003
Posts: 8
Hello everyone,I often come to this forum to learn Java,but It is the first time post new topic.
Could someone tell me why the output is 1,1,2?
------------------------------------------------------------------------
class Amber {
public static void main(String[] args) {
int[][] a = {{1,2},{0,1,2},{-1,0,2}};
Object[] obj = (Object[])a.clone();
for(int i = 0; i < obj.length; i++) {
int[] ia = (int[])obj[i];
System.out.println(ia[i]+",");
}
}
}


※Study hard and make progress every day※
◎Java:SCJP,SCWCD,SCBCD,SCDJWS,SCEA
◎Solaris:SCSA
◎Oracle:OCA,OCP
◎PMI:PMP
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Welcome to the JavaRanch and thank you for using my exam.
The program prints the values contained in ia[0][0], ia[1][1] and ia[2][2].


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's Question:clone()
 
Similar Threads
Dan exam doubt in arrays
Cloneable Object
Array of Arrays ???
Array conversion Question from Dan's test
Array Conversion