You are on page 1of 14

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.Which of the following is not a legal name for a variable?
Mark for Review
(1) Points
2bad (*)
zero
theLastValueButONe
year2000

Correct
2.Select the declaration and initialization statement that will hold the
Mark for Review
letter J.
(1) Points
int letter='J';
float letter='J';
String letter='J';
char letter='J'; (*)

Correct
3.A _______________ is used to organize Java related files.
Mark for Review
(1) Points
Project
Workspace
Package (*)
Collection

Correct
4.A combination of views and editors are referred to as
Mark for Review
_______________.
(1) Points
A workspace
A physical location
A perspective (*)
All of the above

Correct
5.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. (*)

Correct

Section 4
(Answer all questions in this section)
6. Eclipse does not provide views to help you navigate a hierarchy of
Mark for Review
information. True or False?
(1) Points
True
False (*)

Correct
7. Multiple windows are used when more than one file is open in the
Mark for Review
edit area. True or False?
(1) Points
True
False (*)

Correct
8. Given the code:
Mark for Review
(1) Points
String s = new String("abc");

Which of the following statements will change the length of s to the


largest length?
s.trim()
s.replace("a", "aa")
s.substring(2)
s.toUpperCase()
None of the above will change the length of s. (*)
Correct
9. The == operator tests if two String references are pointing to the
Mark for Review
same String object. True or false?
(1) Points
True (*)
False

Correct
10.Which of the following creates a String reference named s and
Mark for Review
instantiates it?
(1) Points
(Choose all correct answers)
String s=""; (*)
s="s";
String s;
String s=new String("s"); (*)

Correct

Section 4
(Answer all questions in this section)
11.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
12.The following code is an example of creating a String reference:
Mark for Review
(1) Points
String s;

True or false?
True (*)
False

Correct
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.
Provides the compiler information that identifies outside classes
used within the current class. (*)
Precedes the name of the class.

Correct
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

Section 5
(Answer all questions in this section)
15.A counter used in a for loop cannot be initialized within the For loop
Mark for Review
header. True or false?
(1) Points
True
False (*)

Correct

Section 5
(Answer all questions in this section)
16.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 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. (*)
A loop that contains a counter in parenthesis with the conditional
statement.
Correct
17.In a for loop the counter is not automatically incremented after each
Mark for Review
loop iteration. Code must be written to increment the counter. True
(1) Points
or false?
True (*)
False

Correct
18.switch statements work on all input types including, but not limited
Mark for Review
to, int, char, and String. True or false?
(1) Points
True
False (*)

Correct
19.Determine whether this boolean expression evaluates to true or false:
Mark for Review
(1) Points
!(3<4&&6>6||6<=6&&7-2==6)
True (*)
False

Correct
20.The three logic operators in Java are:
Mark for Review
(1) Points
&&, ||, ! (*)
!=,=,==
&&,!=,=
&,|,=

Correct

Section 6
(Answer all questions in this section)
21What is the output of the following segment of code?
Mark for
.
Review
(1) Points
321111
11 (*)
111
1111
This code doesn't compile.

Incorrect. Refer to Section 6 Lesson 1.


22Which of the following declares and initializes a one dimensional array
Mark for
. named values of size 5 so that all entries contain 1?
Review
(1) Points
int[] values={1,1,1,1,1}; (*)
int[] values={1};
int values={1,1,1,1,1};
int values[]={1,1,1,1,1,1};

Incorrect. Refer to Section 6 Lesson 1.


23The following segment of code initializes a 2 dimensional array of
Mark for
. primitive data types. True or false?
Review
(1) Points
double[][] a=new double[4][5];
True (*)
False

Correct
24Which of the following statements adds 5 to every element of the one
Mark for
. dimensional array prices and then prints it to the screen?
Review
(1) Points
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
System.out.println(prices[i]+5);
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);
Incorrect. Refer to Section 6 Lesson 1.
25Which searching algorithm involves using a low, middle, and high index
Mark for
. value to find the location of a value in a sorted set of data (if it exists)?
Review
(1) Points
Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above

Correct

Section 6
(Answer all questions in this section)
26.A sequntial search is an iteration through the array that stops at the
Mark for Review
index where the desired element is found. True or false?
(1) Points
True (*)
False

Correct
27.Bubble Sort is a sorting algorithm that involves swapping the
Mark for Review
smallest value into the first index, finding the next smallest value and
(1) Points
swapping it into the next index and so on until the array is sorted.
True or false?
True
False (*)

Correct
28.Which of the following is a sorting algorithm that involves
Mark for Review
repeatedly incrementing through the array and swapping 2 adjacent
(1) Points
values if they are in the wrong order until all elements are in the
correct order?
Selection Sort
Merge Sort
Bubble Sort (*)
Sequential Search
Binary Search

Correct
29.If an exception is thrown by a method, where can the catch for the
Mark for Review
exception be?
(1) Points
There does not need to be a catch in this situation.
The catch must be in the method that threw the exception.
The catch can be in the method that threw the exception or in
any other method that called the method that threw the
exception. (*)
The catch must be immediately after the throw.

Correct

Section 7
(Answer all questions in this section)
30.All objects, in Java, are created using int. True or false?
Mark for Review
(1) Points
True
False (*)

Correct

Section 7
(Answer all questions in this section)
31The basic unit of encapsulation in Java is the primitive data type. True or
Mark for
. false?
Review
(1) Points
True
False (*)

Incorrect. Refer to Section 7 Lesson 1.


32Which of the following calls the method calculate correctly?
Mark for
.
Review
(1) Points

ThisClass t=new ThisClass(); int x=t.calculate(3,4); (*)


int x=calculate(3,4);
ThisClass t=new ThisClass(); int x=t.calculate(3);
ThisClass t=new ThisClass(); int x=t.calculate();
Correct
33Which of the following creates an instance of the class below?
Mark for
.
Review
(1) Points

ThisClass t=new ThisClass();


ThisClass t;
ThisClass t=new ThisClass(3,4);
ThisClass t=new ThisClass(5); (*)

Correct
34Identify the driver class that correctly initializes employees Jane and
Mark for
. Brandon. The Employee class is below.
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
35What operator do you use to call an object's constructor method and create
Mark for
. a new object?
Review
(1) Points
+
new (*)
instanceOf

Correct

Section 7
(Answer all questions in this section)
36.If you inherit a class, you do not inherit the class' constructors. True
Mark for Review
or false?
(1) Points
True (*)
False

Correct
37.If a variable in a superclass is private, could it be directly accessed or
Mark for Review
modified by a subclass? Why or why not?
(1) Points
Yes. A subclass inherits full access to all contents of its super
class.
Yes. Any variable passed through inheritance can be changed,
but private methods cannot.
No. A private variable can only be modified by the same class
with which it is declared regardless of its inheritance. (*)
No. Nothing inherited by the super class can be changed in the
subclass.
Correct
38.What is encapsulation?
Mark for Review
(1) Points
A keyword that allows or restricts access to data and methods.
A programming philosophy that promotes simpler, more
efficient coding by using exiting code for new applications.
A structure that categorizes and organizes relationships among
ideas, concepts of things with the most general at the top and the
most specific at the bottom.
A programming philosophy that promotes protecting data and
hiding implementation in order to preserve the integrity of data
and methods. (*)
Correct
39.Which of the following show the correct UML representation of the
Mark for Review
super class Planet and its subclass Earth?
(1) Points

(*)

None of the above.

Correct
40.Static classes can't return instances of the parent class when the
Mark for Review
parent class uses a private constructor. True or false?
(1) Points
True
False (*)

Incorrect. Refer to Section 7 Lesson 3.

Section 7
(Answer all questions in this section)
41.Public static variables can't have their value reset by other classes.
Mark for Review
True or false?
(1) Points
True
False (*)

Correct
42.A base case can handle nested conditions. True or false?
Mark for Review
(1) Points
True (*)
False

Correct
43.What is Polymorphism?
Mark for Review
(1) Points
A way of redefining methods with the same return type and
parameters.
A way to create multiple methods with the same name but
different parameters.
A class that cannot be initiated.
The concept that a variable or reference can hold multiple types
of objects. (*)
Correct
44.Abstract classes can be instantiated. True or false?
Mark for Review
(1) Points
True
False (*)

Correct
45.If an abstract class does not have implemented constructors or
Mark for Review
methods, it should be implemented as an interface instead. True or
(1) Points
false?
True (*)
False

Correct

Section 7
(Answer all questions in this section)
46.Which segment of code correctly defines a method that contains two
Mark for Review
objects of class Tree as parameters?
(1) Points
void bloom(Tree pine, Tree oak) {//code here }; (*)
Tree bloom (pine, oak) {//code here };
void bloom, Tree pine, Tree oak {//code here };
None of the above, objects cannot be passed as parameters.

Incorrect. Refer to Section 7 Lesson 2.


47.Which of the following is the correct way to code a method with a
Mark for Review
return type an object Automobile?
(1) Points
Automobile upgrade(String carA){
carA="Turbo";
return carA;}
Automobile upgrade(Automobile carA){
carA.setTurbo("yes");
return carA;} (*)
String upgrade(String carA){
carA="Turbo";
return carA;}
upgrade(Automobile carA) Automobile{
carA.setTurbo("yes");
return carA;}
None of the above. It is not possible to return an object.

Correct
48.Which segment of code represents a correct way to define a variable
Mark for Review
argument method?
(1) Points
String easyArray(String ... elems) {//code} (*)
String easyArray(... String elems) {//code}
String ... easyArray(String elems) {//code}
Integer easyArray ... (int elems) {//code}

Correct
49.It is possible to return an object from a method. True or false?
Mark for Review
(1) Points
True (*)
False

Correct
50.Which segment of code represents a correct way to call a variable
Mark for Review
argument method counter that takes in integers as its variable
(1) Points
argument parameter?
counter(String a, int b);
counter(int[] numbers);
counter(1, 5, 8, 17, 11000005); (*)
counter("one","two",String[] nums);

Correct

You might also like