About Question com.enthuware.ets.scjp.v6.2.197 :
Posted: Wed Jul 18, 2012 8:20 am
Question:
What will be the output of compiling and running the following program?
class CloneTest
{
public static void main(String[] args)
{
int ia[ ][ ] = { { 1 , 2}, null };
int ja[ ][ ] = (int[ ] [ ])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
Answer:
It will print 'false true' when run.
Explanation:
A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared, so ia and ja are different but ia[0] and ja[0] are same.
why? how prints false in the first operation? The Explanation said: "is[0] and ja[0] are same!" someone help me?
What will be the output of compiling and running the following program?
class CloneTest
{
public static void main(String[] args)
{
int ia[ ][ ] = { { 1 , 2}, null };
int ja[ ][ ] = (int[ ] [ ])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
Answer:
It will print 'false true' when run.
Explanation:
A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared, so ia and ja are different but ia[0] and ja[0] are same.
why? how prints false in the first operation? The Explanation said: "is[0] and ja[0] are same!" someone help me?