Question

In: Computer Science

45. Which statement correctly passes the array items to method takeArray? Array items contains 10 elements....

45. Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.

a. takeArray(items[9])

b. takeArray(items[])

c. takeArray(items)

d. Arrays cannot be passed to methods – each item must be sent to the method separately.

46. When an argument is passed by reference, ____________.

a. a copy of the argument’s value is passed to the called method

b. the original value is removed from memory

c. changes to the argument do not affect the original variable’s value in the caller

d. the called method can access the argument’s value in the caller directly and modify that data

47. Which of the following statements is false?

a. When an argument is passed by reference, the called method can access the argument’s value in the caller directly and can modify it.

b. To pass an object reference to a method, simply specify in the method call the name of the variable that refers to the object.

c. When an argument is passed by reference, the called method can access the argument’s value in the caller directly but cannot modify it.

d. To pass an individual array element to a method, use the indexed name of the array.

Solutions

Expert Solution

45.

Option c is correct.

  • takeArray(items) correctly passes the array items to method takeArray.
  • No need to declare the size of the array.
  • Array items contains 10 elements, but you need not declare the size.

46.

Option d is correct.

  • The called method can access the argument’s value in the caller directly and modify that data.
  • The called by reference approach uses the address operator that is &
  • Any changes to the arguments by the called function that is effected to the original values in main.
  • When an argument is passed by reference, the called method can access the argument’s value in the caller directly and can modify it.
  • Since we access through addressss the values are directly affected.

47.

Option c correct.

False:

When an argument is passed by reference, the called method can access the argument’s value in the caller directly but cannot modify it.

Reason:

  • The called by reference approach uses the address operator that is &
  • Any changes to the arguments by the called function that is effected to the original values in main.
  • When an argument is passed by reference, the called method can access the argument’s value in the caller directly and can modify it.
  • Since we access through addressss the values are directly affected.

Related Solutions

Which of these items are elements of a typical scope statement?
 Which of these items are elements of a typical scope statement? (You may select more than one answer. Single click the box with the question mark to produce a check mark for a correct answer and double click the box with the question mark to empty the box for a wrong answer.) List of stakeholders Initiation date Limits and exclusions Reviews with customer Technical requirements Project Leadership
On the following code that contains a method which returns a new matrix (2-d array) with...
On the following code that contains a method which returns a new matrix (2-d array) with same number of rows and columns as has its parameter (matrix). Each entry in the returned array should equal the result of multiplying the entry at the same row and column in matrix by the value of scalar. code: package edu.buffalo.cse116; /** * Class which contains a method which takes in a 2-dimensional array and a scalar value and returns their product. */ public...
A box contains 10 items, of which 3 are defective and 7 are non-defective. Two items...
A box contains 10 items, of which 3 are defective and 7 are non-defective. Two items are randomly selected, one at a time, with replacement, and x is the number of defective items in the sample. To look up the probability of a defective item being drawn from the box, using a binomial probability table, what would be the values of n, x and p to look up?
7) A shipment of 10 items contains 4 items which are defective. If we randomly select...
7) A shipment of 10 items contains 4 items which are defective. If we randomly select 4 of the items for inspection, what is the probability of at least 3 non-defective items in the sample? Assume sampling without replacement. a) 185/210 b) 184/210 c) 25/210 d) 115/210* e) 175/210
The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly.
  The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly. public static void reverse(int[] a, int index) {       if (index == (a.length - 1))         System.out.printf("%d%n", a[index]);       else {          reverse(a, index); What does it do? Explain why it behaves in this way.                                    There is more than one error in the code. Correct the code so that it will recursively print out...
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we...
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we will call our visible field, needs to be 5 by 5 and should initially hold the underscore character “_”.  This will be used in our game of minesweeper to represent the possible locations the player can check. The second array, which we will call our hidden field, should also be 5 by 5 but filled with the capital letter "S” which means safety. However, we...
A lot of 100 items contains 10% which are defective and 90% nondefective. Two are chosen...
A lot of 100 items contains 10% which are defective and 90% nondefective. Two are chosen at random. Let A = {the first item non defective}, B = {the second item non defective}. Find P(B) and show P(B) = P(A). Why is this?
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
Based on a sample of 150 items, in which 45 items exhibited the trait deemed to...
Based on a sample of 150 items, in which 45 items exhibited the trait deemed to be a success, when constructing a 90% confidence interval... a) ...what is the low-end value of the confidence interval? (ANSWER AS A PERCENT TO 2 DECIMALS) b) ...what is the high-end value of the confidence interval? (ANSWER AS A PERCENT TO 2 DECIMALS) c) ...is it reasonable to assume the population proportion is 36%? (Y or N)
Based on a sample of 150 items, in which 45 items exhibited the trait deemed to...
Based on a sample of 150 items, in which 45 items exhibited the trait deemed to be a success, when constructing a 99% confidence interval... a) ...what is the low-end value of the confidence interval? (ANSWER AS A PERCENT TO 2 DECIMALS) b) ...what is the high-end value of the confidence interval? (ANSWER AS A PERCENT TO 2 DECIMALS) c) ...is it reasonable to assume the population proportion is 41%? (Y or N)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT