Consider the following class definition.public class Toy{private int yearFirstSold;public int getYearFirstSold(){return yearFirstSold;}/* There may be instance variables, constructors, and other methods not shown. */}The following code segment, which appears in a class other than Toy, prints the year each Toy object in toyArray was first sold by its manufacturer. Assume that toyArray is a properly declared and initialized array of Toy objects.for (Toy k : toyArray){System.out.println(k.getYearFirstSold());}Which of the following could be used in place of the given code segment to produce the same output?I.for (int k = 0; k < toyArray.length; k++){System.out.println(getYearFirstSold(k));}II.for (int k = 0; k < toyArray.length; k++){System.out.println(k.getYearFirstSold());}III.for (int k = 0; k < toyArray.length; k++){System.out.println(toyArray[k].getYearFirstSold());}A: I onlyB: II onlyC: III onlyD: I and IIE: II and III2. Consider the following two code segments.I.int[] arr = {1, 2, 3, 4, 5};for (int x = 0; x < arr.length; x++){System.out.print(arr[x + 3]);}II.int[] arr = {1, 2, 3, 4, 5};for (int x : arr){System.out.print(x + 3);}Which of the following best describes the behavior of code segment I and code segment II ?A: Both code segment I and code segment II will print 45.B: Both code segment I and code segment II will print 45678.C: Code segment I will cause an ArrayIndexOutOfBoundsException and code segment II will print 45.D: Code segment I will cause an ArrayIndexOutOfBoundsException and code segment II will print 45678.E: Both code segment I and code segment II will cause an ArrayIndexOutOfBoundsException.3. The code segment below is intended to set the boolean variable duplicates to true if the int array arr contains any pair of duplicate elements. Assume that arr has been properly declared and initialized.boolean duplicates = false;for (int x = 0; x < arr.length - 1; x++){/* missing loop header */{if (arr[x] == arr[y]){duplicates = true;}}}Which of the following can replace /* missing loop header */ so that the code segment works as intended?A: for (int y = 0; y <= arr.length; y++)B: for (int y = 0; y < arr.length; y++)C: for (int y = x; y < arr.length; y++)D: for (int y = x + 1; y < arr.length; y++)E: for (int y = x + 1; y <= arr.length; y++)4. In the code segment below, assume that the int array numArr has been properly declared and initialized. The code segment is intended to reverse the order of the elements in numArr. For example, if numArr initially contains {1, 3, 5, 7, 9}, it should contain {9, 7, 5, 3, 1} after the code segment executes./* missing loop header */{int temp = numArr[k];numArr[k] = numArr[numArr.length - k - 1];numArr[numArr.length - k - 1] = temp;}Which of the following can be used to replace /* missing loop header */ so that the code segment works as intended?A: for (int k = 0; k < numArr.length / 2; k++)B: for (int k = 0; k < numArr.length; k++)C: for (int k = 0; k < numArr.length / 2; k--)D: for (int k = numArr.length - 1; k >= 0; k--)E: for (int k = numArr.length - 1; k >= 0; k++)