Exam # 2 Part 1 Petel Name 1) What will be the output of the following code snip
ID: 3704455 • Letter: E
Question
Exam # 2 Part 1 Petel Name 1) What will be the output of the following code snippet? intl array new int[25]: System.out.printin(array.length): a) 26 b) 24 c) 25 d) This code will result in a compile time error. e) This code will result in a run time error 2) Which of the following is a true statement? a) Arrays are passed as parameters to methods like primitive types. b) Arrays are passed as parameters to methods like object types c) Arrays cannot be passed as parameters to methods. d) All of the above are true. e) None of the above are true. 3) Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not correctly process each element in the array. a) for(int i 0; i names.length; i++) b) for(String name: names) c) for(int i-o; iExplanation / Answer
Answer 1: c) 25
It will print the length of the array.
Answer 2: b) Arrays are passed as parameters to methods like objects.
Arrays are passed to methods by reference or object types which mean that if the elements of the array is changed in a method, then the change will be reflected in the calling method.
Answer 3: c) for(int i=0; i<names.length();i++)
This will give a syntax error, because length is not a function so would not followed by parenthesis.
Answer 4: b) num=numbers[0][1];
Answer 5: c) The value variable will contain the lowest value in the numbers array.
Because first element of the array is assigned to variable value then it will check the remaining array elements one by one with the value of the value variable, if it find less than the value of the value variable, then value will change to that number. so at last, it will print the lowest value of the array.
Answer 6: a) The value variable will contain the sum of all the values in the numbers array.
Answer 7: d)
Answer 8: a)
Answer 9: e) It returns the index of the child who sold the most candy bars
Answer 10: b)
The declaration BankAccount[] firstEmpireBank; reserves memory space for firstEmpireBank, which itself is a reference variable that points to the BankAccount[ ] object. The statement
firstEmpireBank = new BankAccount[1000]; instantiates the BankAccount[ ] object to be 1000 BankAccount objects.
Answer 11: b) UML
Infact other options do not refer any kind of diagram.
Answer 12: d) private
The private visibility modifier guards against inappropriate data access, and therefore promotes encapsulation.
Answer 13: d) public void setAge(int newAge)
Mutators are methods that change the value of an instance variable, and are often referred to as "setters." Therefore, choice d is the correct answer.
Answer 14: e) this
The this reference always refers to the currently executing object.
Answer 15: c) static
Answer 16: d) the numbers and types of their parameters
Answer 17: a) this is the declaration and initialization of an array that holds 50 integers
The code represents the declaration and initialization of an array that will hold 50 integers. The indexes of this array will begin at 0 and end at 49.
Answer 18: e) this code will result in run-time error.
This code will throw an ArrayIndexOutOfBoundsException, since the last index in this array will be 24. This causes a run-time error.
Answer 19: d) all of the above are valid.
Answer 20: d) argument=args[0];
he System object does not have any methods called getFirstArgument or getArgument, and the args array's index starts at 0.
Answer 21: b) public int average(int ... list)
Answer 22: a) int[][] matrix;
Answer 23: b) num=numbers[0][1];
Answer 24:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.