You are on page 1of 17

Jf quiz section 6

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. 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.

2. What does it mean to catch an exception?


Mark for Review

(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.

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?
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.

4. What do exceptions indicate in Java?


Mark for Review

(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.

Incorrect. Refer to Section 6 Lesson 2.

5. What does the interpreter look for when an exception is thrown?


Mark for Review

(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.

7. What is the output of the following segment of code?

Mark for Review

(1) Points
7766554433221
6
7531 (*)
This code does not compile.
753
Incorrect. Refer to Section 6 Lesson 1.

8. Which of the following declares a one dimensional array named "score"


of type int that can hold 9 values?
Mark for Review

(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

10. Which of the following declares and initializes a two dimensional


array?
Mark for Review

(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?

double z[] = new double[7];


Mark for Review

(1) Points
True (*)
False
Correct

12. What will array arr contain after the following code segment has been
executed?

int [] arr = {5, 4, 2, 1, 0};


for (int i = 1; i < arr.length; i++)
{
arr[i - 1] += arr[i];
}
Mark for Review

(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.

13. The following segment of code initializes a 2 dimensional array of


primitive data types. True or false?

double[][] a=new double[4][5];


Mark for Review

(1) Points
True (*)
False
Correct

14. Which of the following statements is a valid array declaration?


Mark for Review

(1) Points
float average[]; (*)
double[] marks; (*)
int number();
counter int[];
Incorrect. Refer to Section 6 Lesson 1.

15. The following array declaration is valid:

int[] y = new int[5];


Mark for Review

(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

2. Choose the best response to this statement: An error can be handled


by throwing it and catching it just like an exception.
Mark for Review

(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.

3. Which of the following would be a correct way to handle an index out of


bounds exception?
Mark for Review
(1) Points
Throw the exception that prints out an error message. There is no need to
have the catch handle the exception if it has already been thrown.
Rewrite your code to avoid the exception by not permititng the use of an
index that is not inside the array. (*)
Do nothing, it will fix itself.
Throw the exception and catch it. In the catch, set the index to the index
of the array closest to the one that was out of bounds. (*)
Incorrect. Refer to Section 6 Lesson 2.

4. What do exceptions indicate in Java?


Mark for Review

(1) Points
The code was not written to handle all possible conditions. (*)
Exceptions do not indicate anything, their only function is to be thrown.

There are no errors in your code.


A mistake was made in your code. (*)
The code has considered and dealt with all possible cases.
Incorrect. Refer to Section 6 Lesson 2.

5. Which of the following could be a reason to throw an exception?


Mark for Review

(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.

7. What is the output of the following segment of code?

Mark for Review

(1) Points
321111
11 (*)
111
This code doesn't compile.
1111
Incorrect. Refer to Section 6 Lesson 1.

8. What is the output of the following segment of code if the command


line arguments are "a b c d e f g"?

Mark for Review

(1) Points
d
e (*)
This code doesn't compile.
f
c
Incorrect. Refer to Section 6 Lesson 1.

9. After execution of the following statement, which of the following are


true?

int number[] = new int[5];


Mark for Review

(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.

10. The following creates a reference in memory named q that can refer


to eight different doubles via an index. True or false?

double[] q = new double[8];


Mark for Review

(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

12. Which of the following declares a one dimensional array named names


of size 8 so that all entries can be Strings?
Mark for Review

(1) Points
String[] names=new String[8]; (*)
String[] name=String[8];
String names=new String[8];
String[] name=new Strings[8];
Correct

13. Which of the following declares and initializes a one dimensional array


named words of size 3 so that all entries can be Strings?
Mark for Review

(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.

14. double array[] = new double[8];

After execution of this statement, which of the following are true?


Mark for Review

(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.

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 declares and initializes a one dimensional array named
words of size 10 so that all entries can be Strings?

Mark for Review

(1) Points

char[] words=new char[10];

char words=new char[10];


String words=new String[10];

String[] words=new String[10]; (*)


Incorrect. Refer to Section 6 Lesson 1.

2. 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];

Mark for Review

(1) Points

True (*)

False
Correct

3. double array[] = new double[8];

After execution of this statement, which of the following are true?

Mark for Review

(1) Points

array[2] is 8

array[4] is null

array.length is 8 (*)

array[0] is undefined
Correct

4. Which of the following declares a one dimensional array named "score" of


type int that can hold 9 values?

Mark for Review


(1) Points

int[] score;

int score=new int[9];

int score;

int[] score=new int[9]; (*)


Correct

5. Which of the following declares a one dimensional array name scores of type
int that can hold 14 values?

Mark for Review

(1) Points

int[] scores=new int[14]; (*)

int score= new int[14];

int scores;

int[] scores=new scores int[14];


Correct

6. What is the output of the following segment of code?

Mark for Review

(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?

int [] arr = {5, 4, 2, 1, 0};


for (int i = 1; i < arr.length; i++)
{
arr[i - 1] += arr[i];
}
Mark for Review

(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

8. What is the output of the following segment of code?

Mark for Review

(1) Points
555555
This code doesn't compile.
987654
456789
777777 (*)
Incorrect. Refer to Section 6 Lesson 1.

9. The following segment of code initializes a 2 dimensional array of


primitive data types. True or false?

double[][] a=new double[4][5];


Mark for Review

(1) Points
True (*)
False
Correct

10. What will be the content of the array variable table after executing
the following code?

Mark for Review

(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

12. What is wrong with this code?

Mark for Review

(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.

13. Which of the following defines an Exception?


Mark for Review

(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.

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?
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

15. What does it mean to catch an exception?


Mark for Review

(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

You might also like