Professional Documents
Culture Documents
Section 4
(Answer all questions in this section)
1.What is printed by the following code segment?
Mark for
Review
(1) Points
\\\\
\\\\\\\ (*)
\\\\\\\\\\\\\\
\\
Correct
2.Consider the following code snippet.
Mark for
Review
(1) Points
What is printed?
Cayrbniz
CayrbnizCayrbniz
yr (*)
ay
ArrayIndexOutofBoundsException is thrown
Incorrect. Refer to Section 4 Lesson 4.
3.What will the following code segment output?
String s="\\\n\"\n\\\n\"";
System.out.println(s);
Mark for
Review
(1) Points
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Incorrect. Refer to Section 4 Lesson 4.
4.The following program prints "Not Equal". True or false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
5.Which of the following creates a String named Char?
Mark for
Review
(1) Points
char string;
String Char; (*)
char Char;
char char;
String char;
Correct
Section 4
(Answer all questions in this section)
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Perspective
Workspace (*)
Editor
None of the above
Incorrect. Refer to Section 4 Lesson 1.
8. You need to _______________ Java code to generate a .class file
Mark for
Review
(1) Points
Collect
Compile (*)
Package
Assemble
Incorrect. Refer to Section 4 Lesson 1.
9. Eclipse does not provide views to help you navigate a hierarchy of
information. True or False?
Mark for
Review
(1) Points
True
False (*)
Correct
10. For every opening curly brace { there does not need to be a closing curly
brace} for the program to compile without error. True or False?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.
11When
. importi
ng
anothe
r
packag
e into
a class
you
must
import
only
the
packag
e
classes
that
will be
called
and
not the
entire
packag
e. True
or
false?
True
False (*)
Incorrect. Refer to Section 4 Lesson 2.
12. Which of the two diagrams below illustrate the general form of a Java
program?
Mark for
Review
(1) Points
Example A
Example B (*)
Correct
13. 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;
Mark for
Review
(1) Points
Section 5
(Answer all questions in this section)
15. Which of the following is true about a do-while loop?
Mark for
Review
(1) Points
It is a post-test loop.
It is a modified while loop that allows the program to run through the
loop once before testing the boolean condition.
It continues looping until the condition becomes false.
All of the above. (*)
Incorrect. Refer to Section 5 Lesson 2.
(Answer all questions in this section)
16. How many times will the following loop be executed?
What is the value of x after the loop has finished?
What is the value of count after the loop has finished?
int count = 17;
int x = 1;
while(count > x){
x*=3;
count-=3;
}
Mark for
Review
(1) Points
4; 8; 27
3; 27; 8 (*)
5; 27; 8
5; 30; 5
3; 9; 11
Incorrect. Refer to Section 5 Lesson 2.
17. Why are loops useful?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 5 Lesson 1.
19. 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. Refer to Section 5 Lesson 1.
Mark for
Review
(1) Points
321111
11 (*)
111
1111
This code doesn't compile.
Incorrect. Refer to Section 6
Lesson 1.
22. What is the output of the following segment
of code?
Mar
k for
Review
(1) Points
321123
642
642246 (*)
312213
This code doesn't compile.
Correct
23. Which of the following statements is not a
valid array declaration?
Mar
k for
Review
(1) Points
int number[];
float []averages;
double marks[5];
counter int[]; (*)
Incorrect. Refer to Section 6
Lesson 1.
24. What is the output of the following segment
of code if the command line arguments are
"a b c d e f g"?
Mar
k for
Review
(1) Points
f
e (*)
c
d
This code doesn't compile.
Incorrect. Refer to Section 6
Lesson 1.
25. Suppose you misspell a method name when
you call it in your program. Which of the
following explains why this gives you an
exception?
Mar
k for
Review
(1) Points
n
n^2
lg(n) (*)
n*lg(n)
Incorrect. Refer to Section 6 Lesson 2.
27. Selection sort is efficient for large arrays. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
28. Binary searches can be performed on sorted and unsorted data. True or
false?
Mark for
Review
(1) Points
True
False (*)
Correct
29. A sequntial search is an iteration through the array that stops at the
index where the desired element is found. True or false?
Mark for
Review
(1) Points
True (*)
False
Correct
Section 7
(Answer all questions in this section)
30. What is the Java Applet?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
Incorrect. Refer to Section 7 Lesson 4.
34. It is possible to overload a method that is not a constructor. True or False?
Mark for
Review
(1) Points
True (*)
False
Correct
35. Identify the error(s) in the class below. Choose all that apply.
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 5.
40. What is Polymorphism?
Mark for
Review
(1) Points
True (*)
False
Correct
42. Static methods can return any object type. True or false?
Mark for
Review
(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 3.
43. A non-linear recursive method is less expensive than a linear recursive
method. True or false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 3.
44. Forward thinking helps when creating linear recursive methods. True
or false?
Mark for
Review
(1) Points
True
False (*)
Correct
45. What is wrong with the following class declaration?
Mark for
class Account{ ;
private int number;
private String name;;
public Account;
}
Review
(1) Points
Mar
k for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7
Lesson 1.
Mar
k for
Review
(1) Points
(*)
Mar
k for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7
Lesson 1.
50. Identify the driver class that correctly
initializes employees Jane and Brandon. The
Employee class is below.
public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}
public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane",
48, 35.00);
Employee Brandon = new
Employee("Brandon", 36, 20.00);
}
} (*)
public class driver_class {
public static void main(String[] args) {
Employee("Jane", 48, 35.00);
Employee("Brandon", 36, 20.00);
}
}
public class driver_class {
public Employee{
Jane = new Employee("Jane", 48, 35.00);
Brandon = new Employee("Brandon", 36,
20.00);
}
}
public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}
Incorrect. Refer to Section 7
Lesson 1.
Mar
k for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Object
Rectangle
double (*)
String
Incorrect. Refer to Section 4 Lesson 3.
3Which of the following defines an object class?
.
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Example A
Example B (*)
Mark for
Review
(1) Points
True (*)
False
Incorrect. Refer to Section 4 Lesson 4.
6The
. followin
g code is
an
example
of
creating
a String
reference
:
String s;
True or
false?
True (*)
False
Incorrect. Refer to Section 4 Lesson 4.
7. Given the code
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?
s1 == s2
s1 = s2
s3 == s1 (*)
Mark for
Review
(1) Points
s1.equals(s2)
s3.equals(s1)
Correct
8. Consider the following code snippet.
Mark for
Review
(1) Points
What is printed?
0
1 (*)
2
11
12
Incorrect. Refer to Section 4 Lesson 4.
9. 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
Incorrect. Refer to Section 4 Lesson 4.
10. A workspace is:
Mark for
Review
(1) Points
The physical location onto which you will store and save your
files.
The location where all projects are developed and modified.
The location where you can have one or more stored
perspectives.
All of the above. (*)
Incorrect. Refer to Section 4 Lesson 1.
11. A perspective
is described
as:
12. When you open more than one file in Eclipse the
system will __________________.
// (*)
/*
*/
/*/
Incorrect. Refer to Section
4 Lesson 1.
14. A combination of views and editors are referred to as
_______________.
A workspace
A physical location
A perspective (*)
Section 5
(Answer all questions in this section)
15. Which of the following correctly matches the switch
statement keyword to its function?
True
False (*)
Correct
It is a post-test loop.
It is a modified while loop that allows the program
to run through the loop once before testing the
boolean condition.
It continues looping until the condition becomes
false.
All of the above. (*)
Incorrect. Refer to Section 5
Lesson 2.
19. A counter used in a for loop cannot be initialized within
the For loop header. True or false?
True
False (*)
Correct
20. In the code fragment below, the syntax for the for loop's
initialization is correct. True or false?
public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))<br> {System.out.Println
("i: "+i); }
}
}
True
False (*)
Incorrect. Refer to Section 5
Lesson 2.
21. Which of the
following is the
correct
lexicographical
order for the
conents of the int
array?
True
False (*)
Incorrect. Refer to
Section 6 Lesson 2.
23. Of the options below, what is the fastest run-time?
n
n^2
lg(n) (*)
n*lg(n)
Incorrect. Refer to
Section 6 Lesson 2.
24. Why might a sequential search be inefficient?
size 3 so
that all
entries
can be
Strings?
String strings=new String[3];
String[] word={"Over","the","mountain"}; (*)
String[] word=new String[3];
String[] words={"Oracle","Academy"}];
Incorrect. Refer to Section 6 Lesson 1.
27. The following array declaration is valid. True or false?
int k[] = new int[10];
Mark for
Review
(1) Points
True (*)
False
Incorrect. Refer to Section 6 Lesson 1.
28. What will be the content of the array variable table after executing
the following code?
Mark for
Review
(1) Points
111
011
001
100
010
001
100
110
1 1 1 (*)
001
010
100
Correct
29. It is possible to throw and catch a second exception inside a catch
block of code. True or false?
Mark for
Review
(1) Points
True (*)
False
Incorrect. Refer to Section 6 Lesson 3.
Section 7
(Answer all questions in this section)
30. The following statement compiles and executes. What do you know
for certain?
Mark for
Review
(1) Points
tree.grows(numFeet);
numFeet must be an int.
tree must be the name of the class.
grows must be the name of an instance field.
grows must be the name of a method. (*)
tree must be a method.
Correct
3The basic
1.unit of
encapsulat
ion in
Java is the
primitive
data type.
True or
false?
True
False (*)
Correct
32. Instance variable names may only contain letters and digits. True or
false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 1.
33. A class can only have one constructor. True or false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 1.
34. What is the output of the following code segment:
int n = 13;
System.out.print(doNothing(n));
System.out.print(" ", n);
Mark for
Review
(1) Points
Mark for
Review
(1) Points
31
32
10
11 (*)
Incorrect. Refer to Section 7 Lesson 1.
36.Static
methods
can write
to class
variables.
True or
false?
True (*)
False
Incorrect. Refer to Section 7
Lesson 3.
37. Static methods can read instance variables. True or false?
True
False (*)
Incorrect. Refer to Section 7
Lesson 3.
38. Static methods can't act like "setter" methods. True or false?
True
False (*)
Correct
39. If a class is immutable then it must be abstract. True or false?
True
False (*)
Incorrect. Refer to Section 7
Lesson 5.
40. Which of the following can be declared final?
Classes
Methods
Local variables
Method parameters
All of the above (*)
Incorrect. Refer to Section 7
Lesson 5.
41.Consider the following
method of the class
Test:
public static List
returnList(List list)
{
return list;
}
Which of the following
program segments in
True (*)
False
Incorrect. Refer to
Section 7 Lesson 4.
45. If you inherit a class, you do not inherit the
class' constructors. True or false?
True (*)
False
Correct
4Which
6.of the
follow
ing is
the
definit
ion for
a
variabl
e
argum
ent
metho
d?
A way to create a new class.
Specifies accessibility to code.
Having more than one constructor with the same name but
different arguments.
A type of argument that enables calling the same method with a
different number of arguments. (*)
Incorrect. Refer to Section 7 Lesson 2.
47. Which of the following is the definition of a constructor?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
49. Identify the error(s) in the class below. Choose all that apply.
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
3. When a String object is created it must be assigned a value. True or false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
4. Which of the following creates a String reference named s and instantiates
it?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
\\\\
\\\\\\\ (*)
\\\\\\\\\\\\\\
\\
Correct
6. Which line of
Java code
properly
calculates
the area of a
triangle using
A=1/2(b)(h)
where b and
h are Java
primitive
integers?
double A=1/2*b*h;
double A=1/2bh;
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
Incorrect. Refer to Section 4 Lesson 3.
7. What are Java's primitive types?
Mark for
Review
(1) Points
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short
Incorrect. Refer to Section 4 Lesson 3.
8. Which of the following defines a driver class?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Project
Workspace
Package (*)
Collection
Incorrect. Refer to Section 4 Lesson 1.
11. For
every
opening
curly
brace
{ there
does not
need to
be a
closing
curly
brace}
for the
program
to
compile
without
error.
True or
False?
True
False (*)
Correct
12. You can return to the Eclipse Welcome Page by choosing Welcome
from what menu?
Mark for
Review
(1) Points
File
Edit
Help (*)
Close
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.
14. 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
Correct
Section 5
(Answer all questions in this section)
15. How many times will the following loop be executed?
What is the value of x after the loop has finished?
What is the value of count after the loop has finished?
Mark for
Review
(1) Points
16. Why
are
loops
usefu
l?
Mark for
Review
(1) Points
continue; (*)
break;
return;
k+=1;
Correct
18. Consider that a Scanner has been initialized such that:
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Correct
20. The six relational operators in Java are:
Mark for
Review
(1) Points
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
Correct
21The
. followi
ng
create
sa
referen
ce in
memor
y
named
q that
can
refer
to six
differe
nt
integer
s via
an
index.
True or
false?
int[] q
= new
int[8];
True
False (*)
Correct
22. double array[] = new double[8];
Mark for
Mark for
Review
(1) Points
True (*)
False
Correct
24. 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. Refer to Section 6 Lesson 1.
25. Which of the following sorting algorithms utilizes a "divide and conquer"
technique to sort arrays with optimal speed?
Mark for
Review
(1) Points
Sequential Search
Merge Sort (*)
Selection Sort
Binary Search
All of the above
Incorrect. Refer to Section 6 Lesson 2.
26. Which
searchin
g
algorith
m
involves
using a
low,
middle,
and high
index
value to
find the
location
of a
value in
a sorted
set of
data (if it
exists)?
Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above
Correct
27. Binary searches can be performed on sorted and unsorted data. True
or false?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
28. Selection sort is efficient for large arrays. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
29. If an exception has already been thrown, what will the interpreter
read next in the program?
Mark for
Review
(1) Points
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.
The user input.
Incorrect. Refer to Section 6 Lesson 3.
Section 7
(Answer all questions in this section)
30. Which of the following could be a reason to return an object?
Mark for
Review
(1) Points
True (*)
False
Mark for
Review
(1) Points
True (*)
False
Correct
33. Which of the following is the correct way to code a method with a
return type an object Automobile?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
tree.grows(nu
mFeet);
numFeet must be an int.
tree must be the name of the class.
grows must be the name of an instance field.
grows must be the name of a method. (*)
tree must be a method.
Incorrect. Refer to Section 7 Lesson 1.
37. The basic unit of encapsulation in Java is the primitive data type. True
or false?
Mark for
Review
(1) Points
True
False (*)
Correct
38. The following code creates an object of type Animal. True or false?
Mark for
False
Incorrect. Refer to Section 7 Lesson 1.
39. What is the output of the following code segment:
int n = 13;
System.out.print(doNothing(n));
System.out.print(" ", n);
Mark for
Review
(1) Points
Mark for
Review
(1) Points
many
copies
of itself
in the
recursiv
e case?
0
1 (*)
2 or more
Correct
42. Static methods can't act like "setter" methods. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
43. Any instance of the same class can assign a new value to a static
variable. True or false?
Mark for
Review
(1) Points
True (*)
False
Correct
44. According to the following class declaration, runSpeed can be modified
in class Cat. True or false?
public class Tiger extends Cat{
public int runSpeed;
}
Mark for
Review
(1) Points
True
False (*)
Correct
45. Which of the following correctly describes the use of the keyword
super?
Mark for
Review
(1) Points
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.
A keyword that allows access from anywhere.
Correct
4Consider creating a class Square that extends
6the Rectangle class provided below. Knowing
. that a square always has the same width and
length, which of the following best represents
a constructor for the Square class?
(*)
None of the above.
Correct
Mar
k for
Review
(1)
Points
Mar
k for
Review
(1)
Points
True (*)
False
Correct
49. Identify the step(s) in creating a Triangle
Applet that displays two triangles.
Mar
k for
Review
(1)
Points
Mar
k for
Review
(1)
Points
Mark for
valid?
2. Suppose that str1 and str2 are two strings. Which of the statements or expressions are
Mark for Review
(1) Points
String str3 = str1 - str2;
str1 += str2; (*)
str1 >= str2
Str1 -= str2;
Correct
3. Which of the following creates a String named Char?
(1) Points
char string;
String Char; (*)
char Char;
char char;
String char;
Correct
4. What will the following code segment output?
String s="\\\n\"\n\\\n\"";
System.out.println(s);
Mark for Review
(1) Points
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Incorrect. Refer to Section 4 Lesson 4.
5. Consider the following code snippet
String forest = new String("Black");
System.out.println(forest.length());
What is printed?
(1) Points
5 (*)
6
7
Black
Forest
Incorrect. Refer to Section 4 Lesson 4.
6. Given the following declaration, which line of Java code properly casts one type into
another without data loss?
int i=3,j=4; double y=2.54;
(1) Points
int x=(double)2.54;
double x=i/j;
double x=(double)(i/j);
double x= double i/j;
(1) Points
Numbers and characters
True and false (*)
Relational and logic operators
Arithmetic and logic operators
Integers and floating point types
Incorrect. Refer to Section 4 Lesson 3.
8. Which of the following defines a driver class?
(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.
Incorrect. Refer to Section 4 Lesson 2.
9. Which of the following defines an object class?
(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.
Incorrect. Refer to Section 4 Lesson 2.
False?
12. Multiple windows are used when more than one file is open in the edit area. True or
Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.
13. What is the purpose of the Eclipse Editor Area and Views?
(1) Points
(Choose all correct answers)
To modify elements. (*)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
Incorrect. Refer to Section 4 Lesson 1.
14. In Eclipse, when you run a Java Application, the results are displayed in a new
window. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
Section 5 (Answer all questions in this section)
15. 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++){<br> if(i%2 == 0)
//your answer here
else
k+=3;
}
Mark for Review
(1) Points
continue; (*)
break;
return;
k+=1;
Incorrect. Refer to Section 5 Lesson 2.
16. Updating the input of a loop allows you to implement the code with the next element rather
than repeating the code always with the same element. True or false?
Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 5 Lesson 2.
17. When the for loop condition statement is met the construct is exited. True or false?
Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 5 Lesson 2.
18. 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.next(); (*)
String input = in.close();
String input = new String in.next();
String input = in.nextInt();
Incorrect. Refer to Section 5 Lesson 1.
19. How would you use the ternary operator to rewrite this if statement?
if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr.");
(1) Points
System.out.print( (gender == "female") ? "Mr." : "Ms." );
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
Correct
20. 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. Refer to Section 5 Lesson 1.
21. It is possible to throw and catch a second exception inside a catch block of code. True or
false?
Mark for Review
(1) Points
True (*)
False
Correct
22. The following segment of code initializes a 2 dimensional array of primitive data
types. True or false?
double[][] a=new double[4][5];
(1) Points
True (*)
False
Incorrect. Refer to Section 6 Lesson 1.
23. What will be the content of the array variable table after executing the following
code?
Correct
25. What is the output of the following segment of code?
int array[][] = {{1,2,3},{3,2,1}};
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
System.out.print(2*array[1][1]);
(1) Points
444444 (*)
123321
246642
222222
This code doesn't compile.
Incorrect. Refer to Section 6 Lesson 1.
26. Of the options below, what is the fastest run-time?
(1) Points
n
n^2
lg(n) (*)
n*lg(n)
Incorrect. Refer to Section 6 Lesson 2.
27. Which of the following is the correct lexicographical order for the conents of the int
array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}
(1) Points
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
29. Selection sort is a sorting algorithm that involves finding the minimum value in the
list, swapping it with the value in the first position, and repeating these steps for the remainder of
the list. True or false?
Mark for Review
(1) Points
True (*)
False
Correct
Section 7 (Answer all questions in this section)
implementation of a public access modifier for the method divide.
(1) Points
divide(int a, int b, public) {return a/b;}
public divide(int a, int b) {return a/b;} (*)
divide(int a, int b) {public return a/b;}
divide(public int a, public int b) {return a/b;}
Incorrect. Refer to Section 7 Lesson 2.
31. Which of the following could be a reason to return an object?
(1) Points
Because you wish to be able to use that object inside of the method.
Mark
(1) Points
They keep track of where you are in your program.
They restrict a superclass to only have one subclass.
They organize constructors and methods in a simplified fashion.
They are used to organize the relationship between a superclass and its subclasses. (*)
Correct
37. Which of the following correctly describes an "is-a" relationship?
Mark for
Review
(1) Points
A helpful term used to conceptualize the relationships among nodes or leaves in an
inheritance hierarchy. (*)
A programming philosophy that promotes simpler, more efficient coding by using exiting
code for new applications.
It restricts access to a specified segment of code.
A programming philosophy that promotes protecting data and hiding implementation in
order to preserve the integrity of data and methods.
Incorrect. Refer to Section 7 Lesson 4.
38. Why is it not possible to extend more than one class at a time in an inheritance
hierarchy chain?
Mark for Review
(1) Points
It is not necessary considering all public content is passed from super class to subclass and
further to their subclass and that subclass' subclass and so on. (*)
Because the computer cannot handle code that complex.
To prevent confusion for the programmer.
It is possible to extend more than one class at a time.
Correct
39. The following code creates an object of type Horse:
Whale a=new Whale();
Mark for Review
(1) Points
True
False (*)
Correct
40. A constructor is used to create objects. True or false?
(1) Points
True (*)
False
Correct
41. The constructor method must always have at least one parameter. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
42. The basic unit of encapsulation in Java is the primitive data type. True or false?
Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 1.
43. What is true about the code below:
Car car1=new Car();
Car car2=new Car();
car2=car1;
(1) Points
True (*)
False
Correct
45. If an abstract class does not have implemented constructors or methods, it should be
implemented as an interface instead. True or false?
Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 5.
46. Abstract class cannot extend another abstract class. True or false?
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 5.
(1) Points
Classes
Methods
Local variables
Method parameters
All of the above (*)
Correct
48. A non-linear recursive method calls how many copies of itself in the recursive case?
Mark for Review
(1) Points
0
1
2 or more (*)
Correct
49. Static classes can extend their parent class. True or false?
(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 3.
50. Static methods can write to instance variables. True or false?
(1) Points
True
False (*)
Correct
1. The String methods equals and compareTo perform similar functions and differ in thei
True (*)
False
Correct
2. Consider the following code snippet.
What is printed?
88888 (*)
88888888
1010778
101077810109
ArrayIndexOutofBoundsException is thrown
Incorrect. Refer to Section 4 Lesson 4.
3. What is printed by the following code segment?
alligator (*)
albatross alligator
albatross
a1
Correct
4. Which of the following creates a String named Char?
char string;
String Char; (*)
char Char;
char char;
String char;
Incorrect. Refer to Section 4 Lesson 4.
5. The following program prints "Not Equal":
True or false?
True (*)
False
Correct
Page 1 of 10
9. You can return to the Eclipse Welcome Page by choosing Welcome from
File
Edit
Help (*)
Close
Incorrect. Refer to Section 4 Lesson 1.
10. Multiple windows are used when more than one file is open in the edit a
True
False (*)
Correct
Page 2 of 10
12. When you open more than one file in Eclipse the system will _________
Section 5
(Answer all questions in this section)
15. Why are loops useful?
16. A counter used in a for loop cannot be initialized within the For loop header. T
True
False (*)
Incorrect. Refer to Section 5 Lesson 2.
17. In a for loop the counter is not automatically incremented after each loop itera
True (*)
False
Correct
18. How would you use the ternary operator to rewrite this if statement?
if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr.");
19. switch statements work on all input types including, but not limited to, int, cha
True
False (*)
Correct
20. Which of the two diagrams below illustrate the correct syntax for variables us
Example A (*)
Example B
Incorrect. Refer to Section 5 Lesson 1.
Page 4 of 10
21. Suppose you misspell a method name when you call it in your program.
22. Which of the following sorting algorithms utilizes a "divide and conque
Sequential Search
Merge Sort (*)
Selection Sort
Binary Search
All of the above
Incorrect. Refer to Section 6 Lesson 2.
True (*)
False
Incorrect. Refer to Section 6 Lesson 2.
24. Why might a sequential search be inefficient?
25. Selection sort is a sorting algorithm that involves finding the minimum v
True (*)
False
Correct
Page 5 of 10
26. Which of the following declares and initializes a one dimensional array named
27. The following segment of code prints all five of the command line arguments e
True
False (*)
Correct
28. The following creates a reference in memory named q that can refer to six diffe
int[] q = new int[8];
True
False (*)
Incorrect. Refer to Section 6 Lesson 1.
29. The following creates a reference in memory named q that can refer to eight di
double[] q = new double[8];
True (*)
False
Correct
Section 7
(Answer all questions in this section)
30. Forward thinking helps when creating linear recursive methods. True or false?
True
False (*)
Correct
Page 6 of 10
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 7
(Answer all questions in this section)
31. A static variable is always publicly available. True or false?
True
False (*)
Correct
32. There is only one copy a static class variable in the JVM. True or false?
True (*)
False
Correct
33. The following statement compiles and executes. What do you know for
tree.grows(numFeet);
True (*)
False
35. The basic unit of encapsulation in Java is the primitive data type. True o
True
False (*)
Correct
Page 7 of 10
36. Java's garbage collection is when all references to an object are gone, the memo
True (*)
False
Correct
37. What value will return for j when the setValue method is called?
31
32
10
11 (*)
Incorrect. Refer to Section 7 Lesson 1.
38. Identify the driver class that correctly initializes employees Jane and Brandon. T
public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}
}
public class driver_class {
public Employee{
Jane = new Employee("Jane", 48, 35.00);
Brandon = new Employee("Brandon", 36, 20.00);
}
}
public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}
Incorrect. Refer to Section 7 Lesson 1.
39. Which of the following can be used as a parameter?
43. Which segment of code represents a correct way to call a variable argument me
44. Which of the following show the correct UML representation of the super class
(*)
48. If we override the toString() method with the code below, what would be the re
True
False (*)
Incorrect. Refer to Section 7 Lesson 5.
Page 10 of 10