0

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?

2
  • 1
    Because int[] is an Object, not Object[], whereas an int[][] is an Object[]. Remember, multidimensional arrays in Java are just arrays of arrays; an array is an Object. Commented Jun 17, 2020 at 17:41
  • Replace Object[] obj = arr with Object obj = arr. Commented Jun 17, 2020 at 17:43

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.