This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan's Question:clone()

 
tonghua li
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]+",");
}
}
}
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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].
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic