Java Fundamentals FinalTest Exam
Java Fundamentals FinalTest Exam
Mark for
Review
(1) Points
True
False (*)
Correct
2The following program prints "Not Equal":
.
Mark for
Review
(1) Points
True or false?
True (*)
False
Correct
3Consider the following code snippet.
.
Mark for
Review
(1) Points
What is printed?
Cayrbniz
CayrbnizCayrbniz
yr (*)
ay
ArrayIndexOutofBoundsException is thrown
Correct
4What will the following code segment output?
.
String s="\\\n\"\n\\\n\"";
System.out.println(s);
Mark for
Review
(1) Points
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Correct
5Given 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 (*)
s1.equals(s2)
Mark for
Review
(1) Points
s3.equals(s1)
Correct
Section 4
(Answer all questions in this section)
6. The following defines an import keyword:
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
2bad (*)
zero
theLastValueButONe
year2000
Correct
Mark for
Review
(1) Points
Object
Rectangle
double (*)
String
Correct
10.A workspace can not have more than one stored projects. True or
false?
Mark for
Review
(1) Points
True
False (*)
Correct
Section 4
(Answer all questions in this section)
11.Multiple windows are used when more than one file is open in the
edit area. True or False?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.
12.What symbols are required for a compiler to ignore a comment?
Mark for
Review
(1) Points
// (*)
/*
*/
/*/
Correct
13.You need to _______________ Java code to generate a .class file
Mark for
Review
(1) Points
Collect
Compile (*)
Package
Assemble
Correct
14.What is the purpose of the Eclipse Editor Area and Views?
Mark for
Review
(1) Points
Section 5
(Answer all questions in this section)
15.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 (*)
Correct
Section 5
(Answer all questions in this section)
16.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
Mark for
Review
(1) Points
True (*)
False
Incorrect. Refer to Section 5 Lesson 1.
18.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); }
}
}
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 5 Lesson 2.
19.When the for loop condition statement is met the construct is exited.
True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
20.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. (*)
Correct
Section 6
(Answer all questions in this section)
21Which 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];
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(total); (*)
int total = 0;
for(int i = 1; i
total = total+prices[i];
System.out.println(prices);
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(prices);
Correct
22What is the output of the following segment of code if the command line
. arguments are "a b c d e f g"?
Mark for
Review
(1) Points
f
e (*)
c
d
This code doesn't compile.
Incorrect. Refer to Section 6 Lesson 1.
23What is the output of the following segment of code?
.
Mark for
Review
(1) Points
321123
642
642246 (*)
312213
This code doesn't compile.
Correct
24The following segment of code initializes a 2 dimensional array of
. primitive data types. True or false?
double[][] a=new double[4][5];
True (*)
False
Correct
Mark for
Review
(1) Points
Mark for
Review
(1) Points
It is missing a semicolon.
It does not compile. (*)
It gives you an out of bounds exception.
There is nothing wrong with this code.
Correct
Section 6
(Answer all questions in this section)
26.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
27.Of the options below, what is the fastest run-time?
Mark for
Review
(1) Points
n
n^2
lg(n) (*)
n*lg(n)
Correct
28.Bubble Sort is a sorting algorithm that involves swapping the
smallest value into the first index, finding the next smallest value and
Mark for
swapping it into the next index and so on until the array is sorted.
True or false?
Review
(1) Points
True
False (*)
Correct
29.Why might a sequential search be inefficient?
Mark for
Review
(1) Points
Section 7
(Answer all questions in this section)
30.Which of the following is the correct way to code a method with a
return type an object Automobile?
Mark for
Review
(1) Points
Correct
Section 7
(Answer all questions in this section)
31.Which of the following specifies accessibility to variables, methods,
and classes?
Mark for
Review
(1) Points
Methods
Parameters
Overload constructors
Access modifiers (*)
Incorrect. Refer to Section 7 Lesson 2.
32.Which of the following are access modifiers?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Correct
34.Which segment of code correctly defines a method that contains two
objects of class Tree as parameters?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Correct
38.A linear recursion requires the method to call which direction?
Mark for
Review
(1) Points
Forward
Backward (*)
Both forward and backward
None of the above
Correct
39.There is only one copy a static class variable in the JVM. True or
false?
Mark for
Review
(1) Points
True (*)
False
Correct
40.Static methods can't change any class variable values at run-time.
True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
Section 7
(Answer all questions in this section)
4In Java, an instance field referenced using the this keyword generates a
1.compilation error. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
4A constructor is used to create objects. True or false?
2.
Mark for
Review
(1) Points
True (*)
False
Correct
4A constructor must have the same name as the class where it is declared.
3.True or false?
Mark for
Review
(1) Points
True (*)
False
Correct
4Identify the driver class that correctly initializes employees Jane and
4.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
}
Mark for
Review
(1) Points
Mark for
Review
(1) Points
(*)
Mark for
Review
(1) Points
True
False (*)
Correct
47.Which of the following is the correct way to call an overriden
method needOil() of a super class Robot in a subclass
SqueakyRobot?
Mark for
Review
(1) Points
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
Correct
48.If a variable in a superclass is private, could it be directly accessed or
modified by a subclass? Why or why not?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
(*)
Mark for
Review
(1) Points