Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1)Which one of the following statements is correct about the following code segm

ID: 3547607 • Letter: 1

Question

1)Which one of the following statements is correct about the following code segment?

int[] somearray = new int[6];?for (int i = 1; i < 6; i++)?{?   somearray[i] = i + 1;?}

1.The for loop initializes all the elements of the array

2.The for loop initializes all the elements except the first element.

3.The for loop initializes all the elements except the last element.

4.The for loop initializes all the elements except the first and last elements.

2)Which one of the following statements is true about passing arrays to a method?

1.A copy of all items in the array is passed to a method.

2.Changes made to an arrays in a method are not reflected to the calling method.

3.Arrays are passed by reference to a method, so changes made to an array in a method affect the actual array.

4.Arrays are passed only if size is specified as another parameter.

3)Why is the following method header invalid??   public static int[5] func(int[] array, int[] num)

1.Arrays used as a return type cannot indicate a size.

2.Methods cannot have an array as a return type.

3.Methods cannot have an array as a parameter

4.Methods cannot have two array parameters.

4)Which one of the following is a correct header for a method named passAList with an array of characters as a parameter?

1.public static void passAList(char[10] theArray)

2.public static void passAList(char theArray)

3.public static void passAList(char[] theArray)

4.public static void passAList(theArray)

5)Which one of the following statements is the correct definition for a two-dimensional array of 20 rows and 2 columns of the type integer?

1.int[][] num = new int[20][2];

2.int[][] num = new int[2][20];

3.int[][] num = new int[20,2];

4.int[][] num = new int[2,20];

6)Which one of the following statements is correct for displaying the value in the second row and the third column of a two-dimensional, size 3 by 4 array?

1.System.out.println(arr[1][2]);

2.System.out.println(arr[2][3]);

3.System.out.println(arr[2][1]);

4.System.out.println(arr[3][2]);

7)Consider the following code snippet:?   int[][] arr = {  { 13, 23, 33 },?                         { 14, 24, 34 } };?Identify the appropriate statement to display the value 24 from the given array?

1.System.out.println(arr[1][2]);

2.System.out.println(arr[2][2]);

3.System.out.println(arr[1][1]);

4.System.out.println(arr[2][1]);

8)Consider the following code snippet:?    int[][] arr = { { 1, 2, 3 },?                         { 4, 5, 6 } };?    int val = arr[0][2] + 9)arr[1][2];?    System.out.println(val);?What is the output of the given code snippet on execution?

9

9)Which one of the following is a valid signature of a method with an integer two-dimensional array parameter of size 10 x 10?

1.public static void func(int[][] arr)

2.public static void func(int[10][] arr)

3.public static void func(int[][10] arr)

4.public static void func(int[10, 10] arr)

10)Which type of method modifies the object on which it operates in some way?

1.static

2.private

3.accessor

4.mutator

11)Which type of method returns the value within a private class variable?

1.static

2.private

3.accessor

4.mutator

12)An object stores its data in _____.

1.methods

2.classes

3.verbs

4.instance variables

13)Within an instance method, what reference refers to the implicit parameter (also known as the calling object)?

1.the null object

2.the this reference

3.the void object

4.there is no way to refer to the calling object within an instance method

14)A(n) _______ is shared by all members of the class.

1.instance variable

2.static variable

3.accessor method

4.mutator method

15)If you do not specify a constructor for your class,

1.a run-time error will occur.

2.a compile-time error will occur.

3.a constructor with no parameters is generated.

4.a constructor with parameters for each instance variable is generated.

16)A class object is not created when the class is written, a class object is created when an object of that type is declared with the keyword "new."  This is known as _____.

1.Encapsulation

2.Abstraction

3.Accessibility

4.Instantiation

17)Assuming a Circle class has been defined with a constructor that takes one argument for setting the circle's radius. Which statement declares and creates a Circle of radius 3?

1.Circle c = Circle(3)

2.Circle c = new Circle(3);

3.Circle c.new.Circle(3);

4.c.Circle(3);

18)____ is the process of providing a public interface while hiding implementation details.

1.Encapsulation

2.Instantiation

3.Constructing

4.Initialization

19)In the code below, what method within the Student class will be called when line 2 executes:

line 1)  Student s1 = new Student();

line 2) System.out.println(s1);

1.toString

2.getter

3.setter

4.static

Explanation / Answer

1.The for loop initializes all the elements of the array

Reason: int[] someArray=new int[6] initialises all elements of array.

Q2.

3.Arrays are passed by reference to a method, so changes made to an array in a method affect the actual array.

Q3.

1.Arrays used as a return type cannot indicate a size.