You are on page 1of 18

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 classe

True
False (*)
Correct
2. Which of the following defines a driver class?

Contains a main method and other static methods. (*)


Contains classes that define objects.

Contains a main method, a package, static methods, an


None of the above.
Correct
3. The following code prints 5 "a"'s to the screen:

True
False (*)
Correct
4. Consider the following code snippet.

What is printed?
55555
87658
AtlanticPacificIndianArcticSouthern
Code does not compile
ArrayIndexOutofBoundsException is thrown (*)
Incorrect. Refer to Section 4 Lesson 4.
5. The following program prints "Not Equal":

True or false?
True (*)
False
Correct
Page 1 of 10

Next

Summary

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)

6. The String methods equals and compareTo perform similar functions and

True (*)
False
Correct
7. The == operator tests if two String references are pointing to the same

True (*)
False
Correct

8. Multiple windows are used when more than one file is open in the edit a

True
False (*)

Incorrect. Refer to Section 4 Lesson

9. When you open more than one file in Eclipse the system will ___________

Close the previously opened file.


Use tabs to display all files open. (*)

Put the new file opened in a View area on


None of the above.
Correct

10. In a project, 1 of the classes must contain a main method. True or False?

True (*)
False

Correct

Previous

Next

Page 2 of 10

Summary

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)
11. In Eclipse, when you run a Java Application, the results are displayed in a new

True
False (*)
Correct
12. A combination of views and editors are referred to as _______________.

A workspace
A physical location
A perspective (*)
All of the above
Correct

13. What is the result when the following code segment is compiled and executed
int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p);

Syntax error "sqrt(double) in java.lang.Math ca


4.0 is displayed (*)
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 varia

double a=11^(1/2);
double a=sqrt(11);
int a=Math.sqrt(11);
double 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?

True
False (*)
Correct

Previous

Next

Page 3 of 10

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 5
(Answer all questions in this section)
16. Which of the following could be a reason to use a switch statement in a

Because it allows the code to be run thro

Because it allows the program to run cer


Because it terminates the current loop.

Because it allows the user to enter an inp

Incorrect. Refer to Section 5 Lesson


17. How would you use the ternary operator to rewrite this if statement?
if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr.");

System.out.print( (gender == "female") ?

System.out.print( (gender == "female") ?


(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
Correct

18. All of the following are essential to initializing a for loop, except which on

Initializing the iterator(i).


Having a conditional statement.
Updating the counter.
Having an if statement. (*)
Correct
19. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num);
-2 (*)
1
0
2
Correct

20. A counter used in a for loop cannot be initialized within the For loop hea

True
False (*)
Correct

Previous

Next

Page 4 of 10

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)

21. What will array arr contain after the following code segment has been executed
int [] arr = {5, 4, 2, 1, 0};
for (int i = 1; i < arr.length; i++)<br> {
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
None of the above.
Correct
22. What is the output of the following segment of code?

456789
777777 (*)
555555

987654
This code doesn't compile.
Correct

23. What will be the content of the array variable table after executing the followin

1
0
0
1
0
0
1
1
1
0
0
1

1
1
0
0
1
0
0
1
1
0
1
0

1
1
1
0
0
1
0
0
1 (*)
1
0
0
Incorrect. Refer to Section 6 Lesson 1.

24. The following array declaration is valid. True or false?


int[] y = new int[5];
True (*)
False
Correct
25. A logic error occurs if an unintentional semicolon is placed at the end of a loop

True
False (*)
Correct

Previous

Page 5 of 10

Next

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)

26. Bubble Sort is a sorting algorithm that involves swapping the smallest v

True
False (*)

Incorrect. Refer to Section 6 Lesson

27. Which of the following sorting algorithms utilizes a "divide and conquer"

Sequential Search
Merge Sort (*)
Selection Sort
Binary Search
All of the above

Incorrect. Refer to Section 6 Lesson

28. A sequntial search is an iteration through the array that stops at the ind

True (*)
False
Correct
29. Of the options below, what is the fastest run-time?

n
n^2
lg(n) (*)

n*lg(n)

Incorrect. Refer to Section 6 Lesson

Section 7
(Answer all questions in this section)
30. If Oak extends Tree, it is possible to declare an object such that
Tree grandfatherT = new Oak();
True or false?
True (*)
False
Correct

Previous

Next

Page 6 of 10

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)
31. What does it mean to override a method?

It is a way to create multiple methods wi


It allows an array to contain different obj

It restricts the privacy of the method to o

It is a way of redefining methods of a par


Correct
32. What is the Java keyword final used for in a program?

It restricts a class from being extendable

It permits access to the class variables an

It permits redefining methods of a parent


It terminates the program.
There is no such keyword in Java.
Correct

33. Which of the following correctly describes the use of the keyword super?

A keyword that restricts access to only in

A keyword that allows subclasses to acce

A keyword that signals the end of a progr

A keyword that allows access from anywh


Correct

34. Which of the following demonstrates the correct way to create an applet

public class Battlefield extends Applet{..


public Applet Battlefield{...}
public class Applet extends Battlefield{..
public class Battlefield(Applet){...}
Correct
35. It is possible for a subclass to be a superclass. True or false?

True (*)
False
Correct

Previous

Page 7 of 10

Next

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7

(Answer all questions in this section)


36. Which of the following correctly describes an "is-a" relationship?

A helpful term used to conceptualize the

A programming philosophy that promote

It restricts access to a specified segment

A programming philosophy that promote


Correct

37. A constructor must have the same name as the class where it is declare

True (*)
False
Correct
38. What is the output of the following code segment:
int n = 13;
System.out.print(doNothing(n));
System.out.print(" ", n);
where the code from the method doNothing is:
public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}
1.75, 13
0.571, 21
1.75, 21
0.571, 13 (*)

Incorrect. Refer to Section 7 Lesson

39. What operator do you use to call an object's constructor method and cre

+
new (*)

instanceOf
Correct

40. Identify the driver class that correctly initializes employees Jane and Bra
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", 4
Employee Brandon = new Employee("Bra
}
} (*)
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
}
}
public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}
Correct

Previous

Page 8 of 10

Next

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)

41. What is true about the code below:


Car car1=new Car();
Car car2=new Car();
car2=car1;
(Choose all correct answers)

The references car1 and car2 are pointin

The reference car2 points to an exact cop

There are no more Car objects in memory

There is a Car object that car1 referenced

There is a Car object that car2 referenced

Incorrect. Refer to Section 7 Lesson

42. Which of the following creates a class named Student with one construc

public class Student { private String nam

public class Student private String name;

public class Student { private String nam

public class Student { private String nam


Correct
43. Which of the following is the definition of a constructor?

A keyword that specifies accessibility of c

A special method that is used to assign in

A way to call a method with a variable nu

A variable in a method declaration that g


Correct
44. Which of the following could be a reason to return an object?

Because you wish to be able to use that o


It has faster performance than returning

The method makes changes to the objec

None of the above. It is not possible to re


Correct
45. It is possible to return an object from a method. True or false?

True (*)
False
Correct

Previous

Next

Page 9 of 10

Summary

Test: Java Fundamentals Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)

46. Which segment of code represents a correct way to define a variable arg

String easyArray(String ... elems) {//code

String easyArray(... String elems) {//code

String ... easyArray(String elems) {//code

Integer easyArray ... (int elems) {//code}


Correct
47. How is it possible for overloading to work?

There is no such thing as overloading.


The code has to be declared as private.

The interpreter doesn't care what you na

Java Virtual Machine searches until it find


Correct

48. Forward thinking helps when creating linear recursive methods. True or f

True
False (*)
Correct

49. Static classes can have different access specifiers than the parent class.

True (*)
False
Correct
50. A static variable is always publicly available. True or false?

True
False (*)
Correct

Previous

Page 10 of 10

Summary

Test Summary: Java Fundamentals Final Exam


Click a question to return to it. You will see the response that was entered and whether or not the
response was correct. If the response was incorrect the correct answer will be displayed.
Answered

Unanswered

Revie Statu
w
s Question
Section 4
When importing another
packa...

Mandator
y?

Points
Points
Available Awarded
14

12

Yes

Which of the following defin... Yes


The following code prints 5
"...
Yes
Consider the following code
s...
Yes
The following program
prints ...
Yes
The String methods equals
an...
Yes
The == operator tests if
two...
Yes
Multiple windows are used
whe...
Yes
When you open more than
one ...
Yes

In a project, 1 of the classe... Yes

In Eclipse, when you run a J... Yes


A combination of views and
e...
Yes
What is the result when
the ...
Yes

Which line of Java code will... Yes

Yes

Yes

Yes

All of the following are ess... Yes

What is the output of the fo... Yes

A counter used in a for loop... Yes

Yes

Yes

Yes

Yes

Yes

Bubble Sort is a sorting alg... Yes

Which of the following sorti... Yes

A sequntial search is an ite... Yes


Of the options below, what
i...
Yes

Section 5
The following prints Yes on
t...
Which of the following
could...
How would you use the
ternar...

Section 6
What will array arr contain ...
What is the output of the
fol...
What will be the content of
t...
The following array
declarat...
A logic error occurs if an u...

Section 7

21

19

If Oak extends Tree, it is p...


What does it mean to
overrid...
What is the Java keyword
fin...
Which of the following
corre...
Which of the following
demon...

Yes

Yes

Yes

Yes

Yes

It is possible for a subclass...


Which of the following
corre...
A constructor must have
the ...
What is the output of the
fol...
What operator do you use
to ...

Yes

Yes

Yes

Yes

Yes

Identify the driver class tha... Yes


What is true about the
code ...
Yes
Which of the following
creat...
Yes

Which of the following is th... Yes


Which of the following
could...
Yes

It is possible to return an ...


Which segment of code
repres...

Yes

Yes

How is it possible for overl... Yes


Forward thinking helps
when ...
Yes

Static classes can have diff... Yes

A static variable is always ... Yes