Rohit sarkar
Rohit sarkar

Reputation: 35

Does a primitive type multi dimensional array gets casted to Object type in Java?

How come

int[] arr = new int[5];

Object[] obj = arr;

produces a compilation error while

int[][] arr = new int[5][5];

Object[] obj = arr;

doesn't?

Upvotes: 0

Views: 24

Answers (1)

Andy Turner
Andy Turner

Reputation: 140318

int[] is an Object, so array of int[] is an array of Object.

Upvotes: 1

Related Questions