Professional Documents
Culture Documents
Section 6
(Answer all questions in this section)
1. Suppose you misspell a method name when you call it in your
program. Which of the following explains why this gives you an
exception?
Mark for Review
(1) Points
Because the parameters of the method were not met.
Because the interpreter does not recognize this method since it was never
initialized, the correct spelling of the method was initialized.
Because the interpreter tries to read the method but when it finds the
method you intended to use it crashes.
This will not give you an exception, it will give you an error when the
program is compiled. (*)
Incorrect. Refer to Section 6 Lesson 2.
(1) Points
It means to throw it.
It means there was never an exception in your code.
It means to handle it. (*)
It means you have fixed the error.
Incorrect. Refer to Section 6 Lesson 2.
3. A computer company has one million dollars to give as a bonus to the
employees, and they wish to distribute it evenly amongst them.
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?
Mark for Review
(1) Points
The programmers will have proven their worth in the company because
without them the company wrote faulty code.
An exception will occur because it is not possible to divide by zero. (*)
An unfixable error will occur.
The program will calculate that each employee will receive zero dollars
because there are zero employees.
Incorrect. Refer to Section 6 Lesson 2.
(1) Points
A mistake was made in your code. (*)
The code was not written to handle all possible conditions. (*)
There are no errors in your code.
The code has considered and dealt with all possible cases.
Exceptions do not indicate anything, their only function is to be thrown.
(1) Points
It does not look for anything. It just keeps reading through your code.
A catch statement in the code. (*)
It does not look for anything. It stops interpreting your code.
The end of the code.
Correct
6. 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]);
Mark for Review
(1) Points
987654321
This code doesn't compile.
97531
9630
963 (*)
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
7766554433221
6
7531 (*)
This code does not compile.
753
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
int score=new int[9];
int[] score=new int[9]; (*)
int score;
int[] score;
Correct
9. Which of the following declares and initializes a two dimensional array
named values with 2 rows and 3 columns where each element is a
reference to an Object?
Mark for Review
(1) Points
String[][] values=new String[2][3]; (*)
String[][] values={"apples","oranges","pears"};
String[][] values;
String[][] values=new String[3][2];
Correct
(1) Points
int[][] array={{1,1,1},{1,1,1},{1,1,1}}; (*)
int[][] array={1,1,1},{1,1,1},{1,1,1};
int[][] array={1,1,1,1,1,1,1,1,1};
int[] array={{1,1,1},{1,1,1},{1,1,1}};
Incorrect. Refer to Section 6 Lesson 1.
11. The following creates a reference in memory named z that can refer
to seven different doubles via an index. True or false?
(1) Points
True (*)
False
Correct
12. What will array arr contain after the following code segment has been
executed?
(1) Points
10, 6, 3, 1, 0
9, 6, 3, 1, 0 (*)
None of the above.
9, 6, 1, 3, 0
7, 3, 2, 1, 0
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
True (*)
False
Correct
(1) Points
float average[]; (*)
double[] marks; (*)
int number();
counter int[];
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
True (*)
False
Correct
Test: JF Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.
Section 6
(Answer all questions in this section)
1. Which of the following defines an Exception?
Mark for Review
(1) Points
Code that has no errors and therefore runs smothly.
An interpreter reading your code.
A very severe non-fixable problem with interpreting and running your
code.
A problem that can be corrected or handled by your code. (*)
Correct
(1) Points
False. An error is much more severe than an exception and cannot be
dealt with adequately in a program. (*)
True. Although errors may be more severe than exceptions they can still
be handled in code the same way exceptions are.
True. Errors and exceptions are the same objects and are
interchangeable.
False. Exceptions are caused by a mistake in the code and errors occur for
no particular reason and therefore cannot be handled or avoided.
Incorrect. Refer to Section 6 Lesson 2.
(1) Points
The code was not written to handle all possible conditions. (*)
Exceptions do not indicate anything, their only function is to be thrown.
(1) Points
You have a fatal error in your program.
To eliminate exceptions from disrupting your program. (*)
To make the user interface harder to navigate.
You have encountered a Stack Overflow Error.
Incorrect. Refer to Section 6 Lesson 2.
6. Which of the following declares and initializes a two dimensional array
with 3 rows and 2 columns?
Mark for Review
(1) Points
int[][] a={{1,1,1},{1,1,1}};
int[][] a={{1,1},{1,1},{1,1}}; (*)
int a={{1,1,1},{1,1,1}};
int a={{1,1},{1,1},{1,1}};
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
321111
11 (*)
111
This code doesn't compile.
1111
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
d
e (*)
This code doesn't compile.
f
c
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
number[0] is undefined
number[2] is 0 (*)
number[4] is null
number.length() is 6
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
True (*)
False
Correct
Section 6
(Answer all questions in this section)
11. 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]);
Mark for Review
(1) Points
987654321
963 (*)
This code doesn't compile.
9630
97531
Correct
(1) Points
String[] names=new String[8]; (*)
String[] name=String[8];
String names=new String[8];
String[] name=new Strings[8];
Correct
(1) Points
String[] words={"Over","the","mountain"}; (*)
String[] words=new String[3];
String[] words={"Oracle","Academy"}];
String strings=new String[3];
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
array[4] is null
array[0] is undefined
array[2] is 8
array.length is 8 (*)
Correct
15. What will be the content of the array variable table after executing
the following code?
Mark for Review
(1) Points
100
110
1 1 1 (*)
111
011
001
001
010
100
100
010
001
Incorrect. Refer to Section 6 Lesson 1.
Section 6
(Answer all questions in this section)
1. Which of the following declares and initializes a one dimensional array named
words of size 10 so that all entries can be Strings?
(1) Points
2. The following creates a reference in memory named z that can refer to seven
different doubles via an index. True or false?
(1) Points
True (*)
False
Correct
(1) Points
array[2] is 8
array[4] is null
array.length is 8 (*)
array[0] is undefined
Correct
int[] score;
int score;
5. Which of the following declares a one dimensional array name scores of type
int that can hold 14 values?
(1) Points
int scores;
(1) Points
This code does not compile.
2
0 (*)
220
222220
Incorrect. Refer to Section 6 Lesson 1.
7. What will array arr contain after the following code segment has been
executed?
(1) Points
9, 6, 3, 1, 0 (*)
7, 3, 2, 1, 0
9, 6, 1, 3, 0
10, 6, 3, 1, 0
None of the above.
Correct
(1) Points
555555
This code doesn't compile.
987654
456789
777777 (*)
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
True (*)
False
Correct
10. What will be the content of the array variable table after executing
the following code?
(1) Points
111
011
001
100
110
1 1 1 (*)
001
010
100
100
010
001
Correct
Previous Page 2 of 3 Next
11. If an exception has already been thrown, what will the interpreter
read next in the program?
Mark for Review
(1) Points
The user input.
The next line of the program even if it is not the catch block of code.
Where the program catches the exception. (*)
The end of the program.
Correct
(1) Points
It does not compile. (*)
There is nothing wrong with this code.
It is missing a semicolon.
It gives you an out of bounds exception.
Incorrect. Refer to Section 6 Lesson 2.
(1) Points
Code that has no errors and therefore runs smothly.
A very severe non-fixable problem with interpreting and running your
code.
An interpreter reading your code.
A problem that can be corrected or handled by your code. (*)
Correct
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.
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?
Mark for Review
(1) Points
An unfixable error will occur.
An exception will occur because it is not possible to divide by zero. (*)
The program will calculate that each employee will receive zero dollars
because there are zero employees.
The programmers will have proven their worth in the company because
without them the company wrote faulty code.
Correct
(1) Points
It means you have fixed the error.
It means to handle it. (*)
It means there was never an exception in your code.
It means to throw it.
Correct