Java OCA OCP Practice Question 775

Question

Which of the following correctly declare a variable which can hold an array of 10 integers?

Select 2 options

  • A. int [] myArray
  • B. int [10] myArray
  • C. int myArray []
  • D. Object [] myArray
  • E. Object [10] myArray


Correct Options are  : A C

Note

An array of integers is an Object :

Object obj = new int []{ 1, 2, 3  }; // is valid. 

But it is not an Array of objects.

Object [] o = new int [10]; // is not valid. 

Difference between the placement of square brackets:

int [] i, j; //here i and j are both array of integers. 
int i[], j; //here only i is an array of integers. j is just an integer. 



PreviousNext

Related