Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Arrays deepToString()

807605Jul 4 2007 — edited Jul 4 2007
i got this question from one of the mock tests. And says only 2 & 3 will compile.
import java.util.*;
class DumpArray {
  public static void main(String [] args) {
    int [] a = {7,9,8};
    int [][] aa = {{1,2,3}, {6,5,4}};
    int [][][] aaa = {{{1,2}, {3,4}}, {{5,6},{7,8}}};
    System.out.println(Arrays.deepToString(a));      // 1
    System.out.println(Arrays.deepToString(aa));   // 2
    System.out.println(Arrays.deepToString(aaa));  //3
   }
 }
But, according to me nothing should compile. Because, deepToString method takes Object[] as parameter. As arrays of primitive types are not sub types of Object[] but Object.

Even if a, aa,aaa are arrays of Integer class, 1 and 2 should compile. as the 3 dimension array is not properly initialized.

Please suggest.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2007
Added on Jul 4 2007
13 comments
332 views