Java OCA OCP Practice Question 530

Question

Which of the following are primitives?

int[] myField = new int[0]; 
Integer[] myField2 = new Integer[0]; 
  • A. Only myField
  • B. Only myField2
  • C. Bother myField and myField2
  • D. Neither myField nor myField2


D.

Note

While int is a primitive, all arrays are objects.

One way to tell is that an array has a public instance variable called length.

Another way is that you can assign it a variable of type Object.

Option D is correct.




PreviousNext

Related