int[] y = new int[5];
True (*)
2. double array[] = new double[8];
After execution of this statement, which of the following are true?
array.length is 8 (*)
3. The following array declaration is valid:
int[] y = new int[5];
True (*)
4. The following creates a reference in memory named z that can refer to seven different doubles via an index. True or false?
double z[] = new double[7];
True (*)
5. The following segment of code initializes a 2 dimensional array of primitive data types. True or false?
double[][] a=new double[4][5];
True (*)
6. Which of the following statements print every element of the one dimensional array prices to the screen?
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
7. The following segment of code initializes a 2 dimensional array of references. True or false?
String[][] array={{"a", "b", "C"},{"a", "b", "c"}};
True (*)
8. Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen?
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
9. What is the output of the following segment of code if the command line arguments are "a b c d e f"?
6 (*)
10. The following array declaration is valid. True or false?
int k[] = new int[10];
True (*)
11. If an exception is thrown by a method, where can the catch for the exception be?
The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
12. Which of the following could be a reason to throw an exception?
To eliminate exceptions from disrupting your program. (*)
13. Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception.
False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*)
14. A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them.
The company writes a program to calculate the amount each employee receives, given the number of employees.
Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees.
What will happen to the program if the company enters 0 into the employment number?
(Choose all correct answers)
An exception will occur because it is not possible to divide by zero. (*)
15. What are exceptions used for in Java?
Correcting mistakes made in your code and handling extraordinary cases. (*)
1. Which line of code shows the correct way to throw an exception?
throw new Exception("Array index is out of bounds"); (*)
2. It is possible to throw and catch a second exception inside a catch block of code. True or false?
True (*)
3. What exception message indicates that a variable may have been mispelled somewhere in the program?
variableName cannot be resolved to a variable (*)
4. Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception.
False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*)
5. A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them.
The company writes a program to calculate the amount each employee receives, given the number of employees.
Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees.
What will happen to the program if the company enters 0 into the employment number?
(Choose all correct answers)
An exception will occur because it is not possible to divide by zero. (*)
6. Which of the following declares and initializes a two dimensional array that can hold 6 Object reference types?
Object[][] array=new Object[2][3]; (*)
7. What is the Output of the following segment of code?
666666 (*)
8. The following creates a reference in memory named k that can refer to six different integers via an index. True or false?
int k[]= int[6];
False (*)
9. Which of the following declares a one dimensional array name scores of type int that can hold 14 values?
int[] scores=new int[14]; (*)
10. What is the output of the following segment of code?
int num[]={9,8,7,6,5,4,3,2,1};
for(int i=0;i<9;i=i+3)
System.out.print(num[i]);
963 (*)
11. The following creates a reference in memory named z that can refer to seven different doubles via an index. True or false?
double z[] = new double[7];
True (*)
12. The following array declaration is valid:
int[] y = new int[5];
True (*)
13. Which of the following declares and initializes a one dimensional array that can hold 5 Object reference types?
Object array=new Object[5]; (*)
Tidak ada komentar:
Posting Komentar