1. Select the statement that declares a number of type double and initializes it to 6 times 10 to the 5th power. Mark for Review
(1) Points
double number=6*10^5;
double number=6*10e5;
double number=6(e5);
double number=6e5; (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
2. What are Java's primitive types? Mark for Review
(1) Points
object, byte, string, char, float, int, long and short
boolean, byte, string, thread, int, double, long and short
boolean, thread, char, double, float, int, long and short
boolean, byte, char, double, float, int, long, and short (*)
boolean, thread, stringbuffer, char, int, float, long and short
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
3. What does the following program output?
Mark for Review
(1) Points
total cost: 48
total cost: + 40
"total cost: " 48
"total cost: " 40
total cost: 40 (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
4. What is the output of the following lines of code?
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
-42
0
6
2 (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
5. Which of the following examples of Java code is not correct? Mark for Review
(1) Points
int x=6;
boolean b=1; (*)
char c='r';
double d=4.5;
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
6. What will the following code segment output?
String s="\\\n\"\n\\\n\"";
System.out.println(s);
Mark for Review
(1) Points
\
"
\
" (*)
"
\
"
\
"
"
\" \"
""\
""
\
""
[Correct] Correct
7. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
8. Suppose that str1 and str2 are two strings. Which of the statements or expressions are valid? Mark for Review
(1) Points
str1 += str2; (*)
str1 >= str2
String str3 = str1 - str2;
Str1 -= str2;
[Correct] Correct
9. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Collection
Workspace
Project
Package (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
10. Semi-colons at the end of each line are not required to compile successfully. True or False? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
11. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
12. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
13. The following defines a package keyword: Mark for Review
(1) Points
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
14. When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
15. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
[Correct] Correct
1. Which of the following correctly initializes a for loop that executes 5 times? Mark for Review
(1) Points
for(int i = 1; i < 5; I++)
for(int i = 1; i < 6; i++) (*)
for(int i = 0; i < 5; I++)
for(int i = 0; i == 6; i++)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
2. For both the if-else construct and the for loop, it is true to say that when the condition statement is met, the construct is exited. True or False? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
3. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Updating the counter.
Having an if statement. (*)
Initializing the iterator(i).
Having a conditional statement.
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
4. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
0
2
1
-2 (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
5. In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
7. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){
if(i%2 == 0)
//your answer here
else
k+=3;
} Mark for Review
(1) Points
break;
continue; (*)
k+=1;
return;
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
8. Which of the following are relational operators in Java? Mark for Review
(1) Points
(Choose all correct answers)
< (*)
<= (*)
=
!= (*)
All of the above.
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
9. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Mark for Review
(1) Points
Example A (*)
Example B
[Correct] Correct
10. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 5 > 6 || 6 <= 6 && 7 - 1 == 6) Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
11. How would you use the ternary operator to rewrite this if statement?
if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr."); Mark for Review
(1) Points
(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
System.out.print( (gender == "female") ? "Mr." : "Ms." );
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
12. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
[Correct] Correct
13. The three logic operators in Java are: Mark for Review
(1) Points
&, |, =
&&, ||, ! (*)
&&, !=, =
!=, =, ==
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
14. switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
15. How would you use the ternary operator to rewrite this if statement?
if (balance < 500)
fee = 10;
else
fee = 0; Mark for Review
(1) Points
fee = ( balance < 500) ? 0 : 10;
fee= ( balance < 500) ? 10 : 0; (*)
fee = ( balance > 5) ? 10 : 0;
fee = ( balance >= 5) ? 0 : 10;
fee = ( balance >= 500) ? 10 : 0;
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
1. Which line of code shows the correct way to throw an exception? Mark for Review
(1) Points
throw new Exception("Array index is out of bounds"); (*)
throw 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] Correct
2. Suppose you are writing a program where the user is prompted to the give coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the princess is not found at those coordinates, the user is given a clue that helps them guess coordinates closer to the princess. The user is allowed to enter their new guess of where the princess is.
Assume your program does not take into consideration the possibility that the user may enter coordinates outside of the castle where the princess could not be. What would be the result of the user entering coordinates outside of the castle? How could this be handled in your code? Mark for Review
(1) Points
(Choose all correct answers)
An error would occur. Errors cannot be handled by code.
An exception would occur. This could be handled by throwing an exception in your code if the user enters invalid coordinates. When the exception is caught, the user could be prompted to enter coordinates within the given range of the castle. (*)
An exception would occur. This could be handled by throwing the exception in your code if the user enters invalid coordinates. When the exception is caught, the prince could be moved to the coordinate inside the castle that is closest to those that the user specified. (*)
An exception would occur but could not be handled inside your code. The user would have to restart the program and enter proper coordinates.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
3. Which of the following would give you an array index out of bounds exception? Mark for Review
(1) Points
Using a single equal symbol to compare the value of two integers.
Refering to an element of an array that is at an index less than the length of the array minus one.
Refering to an element of an array that is at an index greater than the length of that array minus one. (*)
Misspelling a variable name somewhere in your code.
Unintentionally placing a semicolon directly after initializing a for loop.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
4. 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 does nothing. Everything that follows the semicolon is interpreted as code outside of the loop. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
5. What does the interpreter look for when an exception is thrown? Mark for Review
(1) Points
A catch statement in the code. (*)
The end of the code.
It does not look for anything. It just keeps reading through your code.
It does not look for anything. It stops interpreting your code.
[Correct] Correct
6. What is the output of the following segment of code?
Mark for Review
(1) Points
666666
This code does not compile.
1286864 (*)
643432
262423242322
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
7. What is the output of the following segment of code?
Mark for Review
(1) Points
312213
This code doesn't compile.
642
321123
642246 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
8. The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
9. Which of the following statements add all of the elements of the one dimensional array prices, and then prints the sum to the screen? Mark for Review
(1) Points
int total = 0;
for(int i = 0; i total+=prices[i];
System.out.println(total); (*)
int total = 0;
for(int i = 0; i total+=prices[i];
int total = 0;
for(int i = 0; i total+=prices[i];
System.out.println(prices);
int total = 0;
for(int i = 1; i total = total+prices[i];
System.out.println(prices);
[Correct] Correct
10. 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=new String[3];
String[] words={"Oracle","Academy"}];
String strings=new String[3];
String[] words={"Over","the","mountain"}; (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
11. 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] Correct
12. 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
String words=new String[10];
char words=new char[10];
String[] words=new String[10]; (*)
char[] words=new char[10];
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
13. 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[2] is 8
array[0] is undefined
array.length is 8 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
14. 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]; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
15. 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[4] is null
number[2] is 0 (*)
number.length() is 6
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
1. Where should the constructor for a superclass be called? Mark for Review
(1) Points
Inside the main method of the subclass.
The last line in the constructor of the subclass.
Anywhere inside the subclass.
The first line of the constructor in the subclass. (*)
The super constructor does not need to be called inside the subclass.
[Incorrect] Incorrect. Refer to Section 7 Lesson 4.
2. Which of the following correctly describes the use of the keyword super? Mark for Review
(1) Points
A keyword that allows access from anywhere.
A keyword that restricts access to only inside the same class.
A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)
A keyword that signals the end of a program.
[Incorrect] Incorrect. Refer to Section 7 Lesson 4.
3. It is possible to extend a class that already exists in Java, such as the Applet class. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
4. What is the Java keyword final used for in a program? Mark for Review
(1) Points
It restricts a class from being extendable and restricts methods from being overridden. (*)
It permits access to the class variables and methods from anywhere.
It permits redefining methods of a parent class inside the child class, with the same name, parameters, and return type.
There is no such keyword in Java.
It terminates the program.
[Correct] Correct
5. If Oak extends Tree, it is possible to declare an object such that
Tree grandfatherT = new Oak();
True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. If a class is immutable then it must be abstract. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 5.
7. It is possible to overload a method that is not a constructor. True or False? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
8. How is it possible for overloading to work? Mark for Review
(1) Points
The code has to be declared as private.
The interpreter doesn't care what you name your constructors.
There is no such thing as overloading.
Java Virtual Machine searches until it finds a constructor name and argument type match. (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 2.
9. Which of the following could be a reason to return an object? Mark for Review
(1) Points
Because you wish to be able to use that object inside of the method.
It has faster performance than returning a primitive type.
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*)
None of the above. It is not possible to return an object.
[Incorrect] Incorrect. Refer to Section 7 Lesson 2.
10. Consider:
public class MyClass{
public MyClass()
{/*code*/}
// more code...}
To instantiate MyClass, what would you write? Mark for Review
(1) Points
MyClass m = new MyClass(); (*)
MyClass m = MyClass();
MyClass m = new MyClass;
MyClass m = MyClass;
[Correct] Correct
11. The following code creates an object of type Animal:
Animal a; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 1.
12. Which of the following is true? Mark for Review
(1) Points
Instance variable names may only contain letters and digits.
The more comments in a program, the faster the program runs.
A class always has a constructor (possibly automatically supplied by the java compiler). (*)
int is the name of a class available in the package java.lang.
In Java, a method declared public generates a compilation error.
[Incorrect] Incorrect. Refer to Section 7 Lesson 1.
13. Static classes can exist as inner classes. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
14. A static variable is always publicly available. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 3.
15. Static methods can write to instance variables. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 3.
1. Select the declaration and initialization statement that will hold the letter J. Mark for Review
(1) Points
String letter='J';
char letter='J'; (*)
float letter='J';
int letter='J';
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
2. Which of the following statements displays 12345?
I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345"); Mark for Review
(1) Points
All of the above. (*)
I only.
I and II only.
II and III only.
None of the above.
[Correct] Correct
3. What is the output of the following lines of code?
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
0
2 (*)
6
-42
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
4. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
4geeks (*)
dgo2sleep
R2d2
to_be_or_not_to_be
[Correct] Correct
5. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
double a=pow(8,5);
double a=Math.pow(5,8); (*)
int a=Math.pow(5,8);
double a=15^8;
int a=Math.pow(8,5);
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
6. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
7. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Collection
Package (*)
Workspace
Project
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
8. A workspace can not have more than one stored projects. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
9. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
auaacauaac
auaac
ArrayIndexOutofBoundsException is thrown
PoliiPolii (*)
Polii
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
10. The following code is an example of a correct initialization statement:
char c="c"; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
11. What is printed by the following code segment?
Mark for Review
(1) Points
\\\\
\\\\\\\\\\\\\\
\\\\\\\ (*)
\\
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
12. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
13. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
14. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
[Correct] Correct
15. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
[Correct] Correct
1. This keyword is used to instruct specific code when the input for a switch statement that does not match any of the cases. Mark for Review
(1) Points
switch
case
break
default (*)
None of the above
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
2. Which of the following are relational operators in Java? Mark for Review
(1) Points
(Choose all correct answers)
< (*)
<= (*)
=
!= (*)
All of the above.
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
3. In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through". Mark for Review
(1) Points
True (*)
False
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
4. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user?s input and sets it equal to a new String called input?
Mark for Review
(1) Points
String input = in.nextInt();
String input = in.next(); (*)
String input = new String in.next();
String input = in.close();
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
5. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. In an if-else construct, the condition to be evaluated must be contained within parentheses. True or False? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
7. Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y) Mark for Review
(1) Points
I only
II only
I and III
II and III
I, II, and III (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
8. Which of the following could be a reason to use a switch statement in a Java program? Mark for Review
(1) Points
Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read in.
Because it allows the code to be run through until a certain conditional statement is true.
Because it terminates the current loop.
[Correct] Correct
9. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){
if(i%2 == 0)
//your answer here
else
k+=3;
} Mark for Review
(1) Points
break;
k+=1;
return;
continue; (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
10. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Updating the counter.
Having a conditional statement.
Initializing the iterator(i).
Having an if statement. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
11. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
1
-2 (*)
2
0
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
12. Why are loops useful? Mark for Review
(1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of times.
They allow for repeating code until a certain argument is met.
All of the above. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
13. What is the function of the word "break" in Java? Mark for Review
(1) Points
It exits the current loop or case statement. (*)
It does not exist in Java.
It continues onto the next line of code.
It stops the program from running.
[Correct] Correct
14. Which of the following best describes a while loop? Mark for Review
(1) Points
A loop that contains a segment of code that is executed before the conditional statement is tested.
A loop that contains a counter in parenthesis with the conditional statement.
A loop that executes the code at least one time even if the conditional statement is false.
A loop that is executed repeatedly until the conditional statement is false. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
15. Which of the following are types of loops in Java? Mark for Review
(1) Points
(Choose all correct answers)
do-while (*)
while (*)
if/else
for (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
1. What is the output of the following segment of code?
Mark for Review
(1) Points
1111
321111
111
This code doesn't compile.
11 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
2. Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen? Mark for Review
(1) Points
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
System.out.println(prices[i]+5);
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
3. 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={"apples","oranges","pears"};
String[][] values=new String[2][3]; (*)
String[][] values=new String[3][2];
String[][] values;
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
4. The following array declaration is valid. True or false?
; int x[] = int[10]; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
5. What is the output of the following segment of code?
Mark for Review
(1) Points
666666 (*)
1286864
262423242322
This code does not compile.
643432
[Correct] Correct
6. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
[Correct] Correct
7. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int[] values={1};
int values={1,1,1,1,1};
int[] values={1,1,1,1,1}; (*)
int values[]={1,1,1,1,1,1};
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
8. Which of the following statements print every element of the one dimensional array prices to the screen? Mark for Review
(1) Points
System.out.println(prices.length);
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
9. The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
10. 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] Correct
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");
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
12. Which of the following defines an Exception? Mark for Review
(1) Points
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. (*)
Code that has no errors and therefore runs smothly.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
13. What do exceptions indicate in Java? Mark for Review
(1) Points
(Choose all correct answers)
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.
A mistake was made in your code. (*)
The code was not written to handle all possible conditions. (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
14. If an exception is thrown by a method, where can the catch for the exception be? Mark for Review
(1) Points
The catch must be in the method that threw the exception.
There does not need to be a catch in this situation.
The catch must be immediately after the throw.
The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
15. 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] Correct
(1) Points
double number=6*10^5;
double number=6*10e5;
double number=6(e5);
double number=6e5; (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
2. What are Java's primitive types? Mark for Review
(1) Points
object, byte, string, char, float, int, long and short
boolean, byte, string, thread, int, double, long and short
boolean, thread, char, double, float, int, long and short
boolean, byte, char, double, float, int, long, and short (*)
boolean, thread, stringbuffer, char, int, float, long and short
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
3. What does the following program output?
Mark for Review
(1) Points
total cost: 48
total cost: + 40
"total cost: " 48
"total cost: " 40
total cost: 40 (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
4. What is the output of the following lines of code?
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
-42
0
6
2 (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
5. Which of the following examples of Java code is not correct? Mark for Review
(1) Points
int x=6;
boolean b=1; (*)
char c='r';
double d=4.5;
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
6. What will the following code segment output?
String s="\\\n\"\n\\\n\"";
System.out.println(s);
Mark for Review
(1) Points
\
"
\
" (*)
"
\
"
\
"
"
\" \"
""\
""
\
""
[Correct] Correct
7. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
8. Suppose that str1 and str2 are two strings. Which of the statements or expressions are valid? Mark for Review
(1) Points
str1 += str2; (*)
str1 >= str2
String str3 = str1 - str2;
Str1 -= str2;
[Correct] Correct
9. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Collection
Workspace
Project
Package (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
10. Semi-colons at the end of each line are not required to compile successfully. True or False? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
11. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
12. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
13. The following defines a package keyword: Mark for Review
(1) Points
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
14. When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
15. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
[Correct] Correct
1. Which of the following correctly initializes a for loop that executes 5 times? Mark for Review
(1) Points
for(int i = 1; i < 5; I++)
for(int i = 1; i < 6; i++) (*)
for(int i = 0; i < 5; I++)
for(int i = 0; i == 6; i++)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
2. For both the if-else construct and the for loop, it is true to say that when the condition statement is met, the construct is exited. True or False? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
3. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Updating the counter.
Having an if statement. (*)
Initializing the iterator(i).
Having a conditional statement.
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
4. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
0
2
1
-2 (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
5. In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
7. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){
if(i%2 == 0)
//your answer here
else
k+=3;
} Mark for Review
(1) Points
break;
continue; (*)
k+=1;
return;
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
8. Which of the following are relational operators in Java? Mark for Review
(1) Points
(Choose all correct answers)
< (*)
<= (*)
=
!= (*)
All of the above.
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
9. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Mark for Review
(1) Points
Example A (*)
Example B
[Correct] Correct
10. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 5 > 6 || 6 <= 6 && 7 - 1 == 6) Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
11. How would you use the ternary operator to rewrite this if statement?
if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr."); Mark for Review
(1) Points
(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
System.out.print( (gender == "female") ? "Mr." : "Ms." );
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
12. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
[Correct] Correct
13. The three logic operators in Java are: Mark for Review
(1) Points
&, |, =
&&, ||, ! (*)
&&, !=, =
!=, =, ==
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
14. switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
15. How would you use the ternary operator to rewrite this if statement?
if (balance < 500)
fee = 10;
else
fee = 0; Mark for Review
(1) Points
fee = ( balance < 500) ? 0 : 10;
fee= ( balance < 500) ? 10 : 0; (*)
fee = ( balance > 5) ? 10 : 0;
fee = ( balance >= 5) ? 0 : 10;
fee = ( balance >= 500) ? 10 : 0;
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
1. Which line of code shows the correct way to throw an exception? Mark for Review
(1) Points
throw new Exception("Array index is out of bounds"); (*)
throw 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] Correct
2. Suppose you are writing a program where the user is prompted to the give coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the princess is not found at those coordinates, the user is given a clue that helps them guess coordinates closer to the princess. The user is allowed to enter their new guess of where the princess is.
Assume your program does not take into consideration the possibility that the user may enter coordinates outside of the castle where the princess could not be. What would be the result of the user entering coordinates outside of the castle? How could this be handled in your code? Mark for Review
(1) Points
(Choose all correct answers)
An error would occur. Errors cannot be handled by code.
An exception would occur. This could be handled by throwing an exception in your code if the user enters invalid coordinates. When the exception is caught, the user could be prompted to enter coordinates within the given range of the castle. (*)
An exception would occur. This could be handled by throwing the exception in your code if the user enters invalid coordinates. When the exception is caught, the prince could be moved to the coordinate inside the castle that is closest to those that the user specified. (*)
An exception would occur but could not be handled inside your code. The user would have to restart the program and enter proper coordinates.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
3. Which of the following would give you an array index out of bounds exception? Mark for Review
(1) Points
Using a single equal symbol to compare the value of two integers.
Refering to an element of an array that is at an index less than the length of the array minus one.
Refering to an element of an array that is at an index greater than the length of that array minus one. (*)
Misspelling a variable name somewhere in your code.
Unintentionally placing a semicolon directly after initializing a for loop.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
4. 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 does nothing. Everything that follows the semicolon is interpreted as code outside of the loop. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
5. What does the interpreter look for when an exception is thrown? Mark for Review
(1) Points
A catch statement in the code. (*)
The end of the code.
It does not look for anything. It just keeps reading through your code.
It does not look for anything. It stops interpreting your code.
[Correct] Correct
6. What is the output of the following segment of code?
Mark for Review
(1) Points
666666
This code does not compile.
1286864 (*)
643432
262423242322
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
7. What is the output of the following segment of code?
Mark for Review
(1) Points
312213
This code doesn't compile.
642
321123
642246 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
8. The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
9. Which of the following statements add all of the elements of the one dimensional array prices, and then prints the sum to the screen? Mark for Review
(1) Points
int total = 0;
for(int i = 0; i total+=prices[i];
System.out.println(total); (*)
int total = 0;
for(int i = 0; i total+=prices[i];
int total = 0;
for(int i = 0; i total+=prices[i];
System.out.println(prices);
int total = 0;
for(int i = 1; i total = total+prices[i];
System.out.println(prices);
[Correct] Correct
10. 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=new String[3];
String[] words={"Oracle","Academy"}];
String strings=new String[3];
String[] words={"Over","the","mountain"}; (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
11. 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] Correct
12. 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
String words=new String[10];
char words=new char[10];
String[] words=new String[10]; (*)
char[] words=new char[10];
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
13. 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[2] is 8
array[0] is undefined
array.length is 8 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
14. 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]; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
15. 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[4] is null
number[2] is 0 (*)
number.length() is 6
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
1. Where should the constructor for a superclass be called? Mark for Review
(1) Points
Inside the main method of the subclass.
The last line in the constructor of the subclass.
Anywhere inside the subclass.
The first line of the constructor in the subclass. (*)
The super constructor does not need to be called inside the subclass.
[Incorrect] Incorrect. Refer to Section 7 Lesson 4.
2. Which of the following correctly describes the use of the keyword super? Mark for Review
(1) Points
A keyword that allows access from anywhere.
A keyword that restricts access to only inside the same class.
A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)
A keyword that signals the end of a program.
[Incorrect] Incorrect. Refer to Section 7 Lesson 4.
3. It is possible to extend a class that already exists in Java, such as the Applet class. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
4. What is the Java keyword final used for in a program? Mark for Review
(1) Points
It restricts a class from being extendable and restricts methods from being overridden. (*)
It permits access to the class variables and methods from anywhere.
It permits redefining methods of a parent class inside the child class, with the same name, parameters, and return type.
There is no such keyword in Java.
It terminates the program.
[Correct] Correct
5. If Oak extends Tree, it is possible to declare an object such that
Tree grandfatherT = new Oak();
True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. If a class is immutable then it must be abstract. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 5.
7. It is possible to overload a method that is not a constructor. True or False? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
8. How is it possible for overloading to work? Mark for Review
(1) Points
The code has to be declared as private.
The interpreter doesn't care what you name your constructors.
There is no such thing as overloading.
Java Virtual Machine searches until it finds a constructor name and argument type match. (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 2.
9. Which of the following could be a reason to return an object? Mark for Review
(1) Points
Because you wish to be able to use that object inside of the method.
It has faster performance than returning a primitive type.
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*)
None of the above. It is not possible to return an object.
[Incorrect] Incorrect. Refer to Section 7 Lesson 2.
10. Consider:
public class MyClass{
public MyClass()
{/*code*/}
// more code...}
To instantiate MyClass, what would you write? Mark for Review
(1) Points
MyClass m = new MyClass(); (*)
MyClass m = MyClass();
MyClass m = new MyClass;
MyClass m = MyClass;
[Correct] Correct
11. The following code creates an object of type Animal:
Animal a; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 1.
12. Which of the following is true? Mark for Review
(1) Points
Instance variable names may only contain letters and digits.
The more comments in a program, the faster the program runs.
A class always has a constructor (possibly automatically supplied by the java compiler). (*)
int is the name of a class available in the package java.lang.
In Java, a method declared public generates a compilation error.
[Incorrect] Incorrect. Refer to Section 7 Lesson 1.
13. Static classes can exist as inner classes. True or false? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
14. A static variable is always publicly available. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 3.
15. Static methods can write to instance variables. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 7 Lesson 3.
1. Select the declaration and initialization statement that will hold the letter J. Mark for Review
(1) Points
String letter='J';
char letter='J'; (*)
float letter='J';
int letter='J';
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
2. Which of the following statements displays 12345?
I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345"); Mark for Review
(1) Points
All of the above. (*)
I only.
I and II only.
II and III only.
None of the above.
[Correct] Correct
3. What is the output of the following lines of code?
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
0
2 (*)
6
-42
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
4. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
4geeks (*)
dgo2sleep
R2d2
to_be_or_not_to_be
[Correct] Correct
5. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
double a=pow(8,5);
double a=Math.pow(5,8); (*)
int a=Math.pow(5,8);
double a=15^8;
int a=Math.pow(8,5);
[Incorrect] Incorrect. Refer to Section 4 Lesson 3.
6. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
7. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Collection
Package (*)
Workspace
Project
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
8. A workspace can not have more than one stored projects. True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 1.
9. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
auaacauaac
auaac
ArrayIndexOutofBoundsException is thrown
PoliiPolii (*)
Polii
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
10. The following code is an example of a correct initialization statement:
char c="c"; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
11. What is printed by the following code segment?
Mark for Review
(1) Points
\\\\
\\\\\\\\\\\\\\
\\\\\\\ (*)
\\
[Incorrect] Incorrect. Refer to Section 4 Lesson 4.
12. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
13. The following defines an import keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class. (*)
[Incorrect] Incorrect. Refer to Section 4 Lesson 2.
14. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
[Correct] Correct
15. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
[Correct] Correct
1. This keyword is used to instruct specific code when the input for a switch statement that does not match any of the cases. Mark for Review
(1) Points
switch
case
break
default (*)
None of the above
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
2. Which of the following are relational operators in Java? Mark for Review
(1) Points
(Choose all correct answers)
< (*)
<= (*)
=
!= (*)
All of the above.
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
3. In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through". Mark for Review
(1) Points
True (*)
False
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
4. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user?s input and sets it equal to a new String called input?
Mark for Review
(1) Points
String input = in.nextInt();
String input = in.next(); (*)
String input = new String in.next();
String input = in.close();
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
5. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
[Correct] Correct
6. In an if-else construct, the condition to be evaluated must be contained within parentheses. True or False? Mark for Review
(1) Points
True (*)
False
[Correct] Correct
7. Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y) Mark for Review
(1) Points
I only
II only
I and III
II and III
I, II, and III (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 1.
8. Which of the following could be a reason to use a switch statement in a Java program? Mark for Review
(1) Points
Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read in.
Because it allows the code to be run through until a certain conditional statement is true.
Because it terminates the current loop.
[Correct] Correct
9. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){
if(i%2 == 0)
//your answer here
else
k+=3;
} Mark for Review
(1) Points
break;
k+=1;
return;
continue; (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
10. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Updating the counter.
Having a conditional statement.
Initializing the iterator(i).
Having an if statement. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
11. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
1
-2 (*)
2
0
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
12. Why are loops useful? Mark for Review
(1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of times.
They allow for repeating code until a certain argument is met.
All of the above. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
13. What is the function of the word "break" in Java? Mark for Review
(1) Points
It exits the current loop or case statement. (*)
It does not exist in Java.
It continues onto the next line of code.
It stops the program from running.
[Correct] Correct
14. Which of the following best describes a while loop? Mark for Review
(1) Points
A loop that contains a segment of code that is executed before the conditional statement is tested.
A loop that contains a counter in parenthesis with the conditional statement.
A loop that executes the code at least one time even if the conditional statement is false.
A loop that is executed repeatedly until the conditional statement is false. (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
15. Which of the following are types of loops in Java? Mark for Review
(1) Points
(Choose all correct answers)
do-while (*)
while (*)
if/else
for (*)
[Incorrect] Incorrect. Refer to Section 5 Lesson 2.
1. What is the output of the following segment of code?
Mark for Review
(1) Points
1111
321111
111
This code doesn't compile.
11 (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
2. Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen? Mark for Review
(1) Points
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
System.out.println(prices[i]+5);
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
3. 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={"apples","oranges","pears"};
String[][] values=new String[2][3]; (*)
String[][] values=new String[3][2];
String[][] values;
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
4. The following array declaration is valid. True or false?
; int x[] = int[10]; Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
5. What is the output of the following segment of code?
Mark for Review
(1) Points
666666 (*)
1286864
262423242322
This code does not compile.
643432
[Correct] Correct
6. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
[Correct] Correct
7. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int[] values={1};
int values={1,1,1,1,1};
int[] values={1,1,1,1,1}; (*)
int values[]={1,1,1,1,1,1};
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
8. Which of the following statements print every element of the one dimensional array prices to the screen? Mark for Review
(1) Points
System.out.println(prices.length);
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
9. The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 1.
10. 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] Correct
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");
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
12. Which of the following defines an Exception? Mark for Review
(1) Points
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. (*)
Code that has no errors and therefore runs smothly.
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
13. What do exceptions indicate in Java? Mark for Review
(1) Points
(Choose all correct answers)
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.
A mistake was made in your code. (*)
The code was not written to handle all possible conditions. (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
14. If an exception is thrown by a method, where can the catch for the exception be? Mark for Review
(1) Points
The catch must be in the method that threw the exception.
There does not need to be a catch in this situation.
The catch must be immediately after the throw.
The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
[Incorrect] Incorrect. Refer to Section 6 Lesson 2.
15. 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] Correct
EmoticonEmoticon