Test Java Fundamentals Final Exam
Test Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 4
(Answer all questions in this section)
1.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 (*)
Correct
Contains a main method, a package, static methods, and classes that define objects.
Correct
True
False (*)
Correct
What is printed?
55555
87658
AtlanticPacificIndianArcticSouthern
True or false?
True (*)
False
Correct
Section 4
(Answer all questions in this section)
6. 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
7. The == operator tests if two String references are pointing to the same String object.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
8. 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 (*)
9. When you open more than one file in Eclipse the system will __________________.
Mark for Review
(1) Points
Close the previously opened file.
Correct
10. In a project, 1 of the classes must contain a main method. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
Section 4
(Answer all questions in this section)
11.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
12.A combination of views and editors are referred to as _______________.
Mark for
Review
(1) Points
A workspace
A physical location
A perspective (*)
Correct
13.What is the result when the following code segment is compiled and executed?
Mark for
int x = 22, y = 10; Review
double p = Math.sqrt( ( x + y ) /2); (1) Points
System.out.println(p);
Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
2.2 is displayed
5.656854249492381 is displayed
ClassCastException
Correct
14.Which line of Java code will assign the value of the square root of 11 to a variable named
a? Mark for
Review
(1) Points
double a=11^(1/2);
double a=sqrt(11);
int a=Math.sqrt(11);
double a=Math.sqrt*11;
Correct
Section 5
(Answer all questions in this section)
15.The following prints Yes on the screen. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
Section 5
(Answer all questions in this section)
16. 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 code to be run through until a certain conditional statement
is true.
Because it allows the program to run certain segments of code and neglect to run
others based on the input given. (*)
Because it terminates the current loop.
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.
Incorrect. Refer to Section 5 Lesson 1.
17. How would you use the ternary operator to rewrite this if statement?
Mark for Review
if (gender == "female") System.out.print("Ms."); (1) Points
else
System.out.print("Mr.");
System.out.print( (gender == "female") ? "Mr." : "Ms." );
Correct
18. All of the following are essential to initializing a for loop, except which one?
Mark for Review
(1) Points
Initializing the iterator(i).
Correct
19. What is the output of the following code segment?
Mark for Review
int num = 7; (1) Points
while(num >= 0)
{
num -= 3;
}
System.out.println(num);
-2 (*)
Correct
20. A counter used in a for loop cannot be initialized within the For loop header. True or
false? Mark for Review
(1) Points
True
False (*)
Correct
Section 6
(Answer all questions in this section)
21.What will array arr contain after the following code segment has been executed?
Mark for
int [] arr = {5, 4, 2, 1, 0}; Review
for (int i = 1; i < arr.length; i++)<br> { (1) Points
arr[i - 1] += arr[i];
}
9, 6, 1, 3, 0
10, 6, 3, 1, 0
9, 6, 3, 1, 0 (*)
7, 3, 2, 1, 0
Correct
456789
777777 (*)
555555
987654
Correct
23.What will be the content of the array variable table after executing the following code?
Mark for
Review
(1) Points
1 1 1
0 1 1
0 0 1
1 0 0
0 1 0
0 0 1
1 0 0
1 1 0
1 1 1 (*)
0 0 1
0 1 0
1 0 0
Incorrect. Refer to Section 6 Lesson 1.
False
Correct
25.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. Mark for
Everything that follows the semicolon is interpreted as code outside of the loop. True or Review
false? (1) Points
True
False (*)
Correct
Section 6
(Answer all questions in this section)
26. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the
first index, finding the next smallest value and swapping it into the next index and so Mark for Review
on until the array is sorted. True or false? (1) Points
True
False (*)
27. 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
Selection Sort
Binary Search
28. 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
n^2
lg(n) (*)
n*lg(n)
Section 7
(Answer all questions in this section)
30. If Oak extends Tree, it is possible to declare an object such that
Mark for Review
Tree grandfatherT = new Oak(); (1) Points
True or false?
True (*)
False
Correct
Section 7
(Answer all questions in this section)
31. What does it mean to override a method?
Mark for Review
(1) Points
It is a way to create multiple methods with the same name but different
parameters.
It allows an array to contain different object types.
It restricts the privacy of the method to only be accessible from inside the same
class.
It is a way of redefining methods of a parent class inside the child class, with the
same name, parameters, and return type. (*)
Correct
It permits redefining methods of a parent class inside the child class, with the
same name, parameters, and return type.
It terminates the program.
Correct
33. 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.
Correct
34. Which of the following demonstrates the correct way to create an applet Battlefield?
Mark for Review
(1) Points
public class Battlefield extends Applet{...} (*)
Correct
False
Correct
Section 7
(Answer all questions in this section)
36. 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.
False
Correct
0.571, 21
1.75, 21
0.571, 13 (*)
39. What operator do you use to call an object's constructor method and create a new
object? Mark for Review
(1) Points
+
new (*)
instanceOf
Correct
40. Identify the driver class that correctly initializes employees Jane and Brandon. The
Employee class is below. Mark for Review
(1) Points
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();
}
}
Correct
Section 7
(Answer all questions in this section)
41. What is true about the code below:
Mark for Review
Car car1=new Car(); (1) Points
Car car2=new Car();
car2=car1;
(Choose all correct answers)
The references car1 and car2 are pointing to two Car Objects in memory.
The reference car2 points to an exact copy of the Car Object that car1 references.
(*)
There are no more Car objects in memory.
There is a Car object that car1 referenced that is now slated for removal by the
garbage collector.
There is a Car object that car2 referenced that is now slated for removal by the
garbage collector. (*)
Incorrect. Refer to Section 7 Lesson 1.
42. Which of the following creates a class named Student with one constructor, and 2
instance variables, name and gpa? Mark for Review
(1) Points
public class Student { private String name; private float gpa; }
public class Student private String name; private float gpa; Student();
public class Student { private String name; private float gpa; Student(){
name="Jane Doe"; gpa=3.0;} } (*)
public class Student { private String name; Student{ name="Jane Doe"; float
gpa=3.0; }
Correct
Correct
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.
Correct
False
Correct
Section 7
(Answer all questions in this section)
46. Which segment of code represents a correct way to define a variable argument
method? Mark for Review
(1) Points
String easyArray(String ... elems) {//code} (*)
Correct
Java Virtual Machine searches until it finds a constructor name and argument type
match. (*)
Correct
48. Forward thinking helps when creating linear recursive methods. True or false?
Mark for Review
(1) Points
True
False (*)
Correct
49. Static classes can have different access specifiers than the parent class. True or false?
Mark for Review
(1) Points
True (*)
False
Correct
50. A static variable is always publicly available. True or false?
Mark for Review
(1) Points
True
False (*)
Correct