Sie sind auf Seite 1von 11

Test: Section 6 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz
(Answer all questions in this section)

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


Mark for
Review
(1) Points

7766554433221
This code does not compile.
6
753
7531 (*)

Correct

2.The following array declaration is valid. True or false?


Mark for
; int x[] = int[10]; Review
(1) Points

True
False (*)

Correct

3.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
This code doesn't compile.
e (*)
f
c

Correct

4.What will array arr contain after the following code segment has been executed?
Mark for
int [] arr = {5, 4, 2, 1, 0}; Review
for (int i = 1; i < arr.length; i++) (1) Points
{
arr[i - 1] += arr[i];
}

9, 6, 3, 1, 0 (*)
10, 6, 3, 1, 0
9, 6, 1, 3, 0
7, 3, 2, 1, 0
None of the above.

Incorrect. Refer to Section 6 Lesson 1.

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


Mark for
Review
(1) Points

1286864 (*)
This code does not compile.
666666
262423242322
643432

Correct
Test: Section 6 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz
(Answer all questions in this section)

6. After execution of the following statement, which of the following are true?
Mark for
int number[] = new int[5]; Review
(1) Points

number[4] is null
number[2] is 0 (*)
number.length() is 6
number[0] is undefined

Correct

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


Mark for
Review
(1) Points

(Choose all correct answers)

float average[]; (*)


counter int[];
int number();
double[] marks; (*)

Correct

8. What is the output of the following segment of code if the command line arguments are "a b c
d e f"? Mark for
Review
(1) Points

This code doesn't compile.


1
6 (*)
5
3

Correct
9. 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;
int score=new int[9];
int[] score=new int[9]; (*)

Incorrect. Refer to Section 6 Lesson 1.

10What is the output of the following segment of code if the command line arguments are
Mark for
. "apples oranges pears"?
Review
(1) Points

pears (*)
oranges
This code does not compile.
args
apples

Correct

Test: Section 6 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz
(Answer all questions in this section)

11. Which line of code shows the correct way to throw an exception?
Mark for Review
(1) Points

throw Exception("Array index is out of bounds");


throw new Exception("Array index is out of bounds"); (*)
new throw Exception("Array index is out of bounds");
throws new Exception("Array index is out of bounds");

Correct

12. A computer company has one million dollars to give as a bonus to the employees, and
they wish to distribute it evenly amongst them. Mark for Review
(1) Points
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. (*)


The program will calculate that each employee will receive zero dollars because
there are zero employees.
An unfixable error will occur.
The programmers will have proven their worth in the company because without
them the company wrote faulty code.

Correct

13. What exception message indicates that a variable may have been mispelled
somewhere in the program? Mark for Review
(1) Points

variableName cannot be resolved to a variable (*)


method methodName(int) is undefined for the type className
Syntax error, insert ";" to complete statement
All of the above

Correct

14. A logic error occurs if an unintentional semicolon is placed at the end of a loop
initiation because the interpreter reads this as the only line inside the loop, a line that Mark for Review
does nothing. Everything that follows the semicolon is interpreted as code outside of (1) Points
the loop. True or false?

True
False (*)
Incorrect. Refer to Section 6 Lesson 2.

15. What does it mean to catch an exception?


Mark for Review
(1) Points

It means to throw it.


It means to handle it. (*)
It means there was never an exception in your code.
It means you have fixed the error.

Correct
Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7 Quiz
(Answer all questions in this section)

1. What is wrong with the following class declaration?


Mark for Review
class Account{ (1) Points
private int number;
private String name;
public Account;
}

There is nothing wrong.


The constructor method has no definition. (*)
Classes cannot include strings.
Classes cannot include mixed data types.

Correct

2. The constructor method must always have at least one parameter. True or false?
Mark for Review
(1) Points

True
False (*)

Correct

3. What is the output of the following code segment:


Mark for Review
int n = 13; (1) Points
System.out.print(doNothing(n));
System.out.print(“ “, n);
where the code from the method doNothing is:
public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}

0.571, 13 (*)
0.571, 21
1.75, 13
1.75, 21

Correct

4. If it is possible to inherit from an abstract class, what must you do to prevent a compiler
error from occurring? Mark for Review
(1) Points

(Choose all correct answers)

It is not possible to inherit from an abstract class.


Declare the child class as abstract. (*)
Create all new methods and variables different from the parent class.
Override all abstract methods from the parent class. (*)

Correct

5. Abstract classes can be instantiated. True or false?


Mark for Review
(1) Points

True
False (*)

Correct
Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7 Quiz
(Answer all questions in this section)

6. Abstract class cannot extend another abstract class. True or false?


Mark for Review
(1) Points
True
False (*)

Correct

7. Static classes can return instances of their parent class. True or false?
Mark for Review
(1) Points

True (*)
False

Correct

8. Public static variables can't have their value reset by other classes. True or false?
Mark for Review
(1) Points

True
False (*)

Correct

9. Static methods can read instance variables. True or false?


Mark for Review
(1) Points

True
False (*)

Correct

10. Where should the constructor for a superclass be called?


Mark for Review
(1) Points

Anywhere inside the subclass.


The last line in the constructor of the subclass.
Inside the main method of the subclass.
The super constructor does not need to be called inside the subclass.
The first line of the constructor in the subclass. (*)

Correct
Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7 Quiz
(Answer all questions in this section)

11.Which of the following is the proper way to set the public variable length of the super class
equal to 5 from inside the subclass? Mark for
Review
(1) Points

super.length = 5 (*)
super(length = 5)
super.length(5)
super.length() = 5

Incorrect. Refer to Section 7 Lesson 4.

12.It is possible for a subclass to be a superclass. True or false?


Mark for
Review
(1) Points

True (*)
False

Correct

13.It is possible to overload a method that is not a constructor. True or False?


Mark for
Review
(1) Points

True (*)
False

Correct
14.Identify the error(s) in the class below. Choose all that apply.
Mark for
Review
(1) Points

(Choose all correct answers)

The parameters must be the same for all methods with the same name.
Two methods cannot have the same name.
Private cannot be used as an access modifier.
Final cannot be used as an access modifier.
No method named min is defined. (*)

Correct

15.Which segment of code represents a correct way to call a variable argument method
counter that takes in integers as its variable argument parameter? Mark for
Review
(1) Points

counter(1, 5, 8, 17, 11000005); (*)


counter(int[] numbers);
counter("one","two",String[] nums);
counter(String a, int b);

Correct

Das könnte Ihnen auch gefallen