You are on page 1of 16

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 statements displays 12345?
I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345");
All of the above. (*)
I only.
I and II only.
II and III only.
None of the above.

Incorrect. Refer to Section


2. What is the output of the following lines of code?
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result);
6
0
-42
2 (*)

Incorrect. Refer to Section

3. Four variables are required to support a conversion of one unit of m

True
False (*)
Correct

4. You can return to the Eclipse Welcome Page by choosing Welcome fr

File
Edit

Help (*)
Close
Correct
5. A perspective is described as:

A combination of views and edito

A combination of views and wind


A combination of editor tabs
None of the above
Correct

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. 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 (*)
Incorrect. Refer to Section 4 Lesson 1.
7. You need to _______________ Java code to generate a .class file

Mark for
Review
(1) Points

Collect
Compile (*)
Package
Assemble
Correct

8. Which of the two diagrams below illustrate the general form of a Java
program?

Mark for
Review
(1) Points

Example A
Example B (*)
Correct
9. Which of the following defines an object 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
10Which of the following creates a String named Char?
.

Mark for
Review
(1) Points

char string;
String Char; (*)
char Char;
char char;
String char;
Correct
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)
11What is printed by the following code segment?
.

Mark for
Review
(1) Points

alligator (*)
albatross alligator
albatross
a1
Correct
12The following program prints "Not Equal". True or false?
.

Mark for
Review
(1) Points

True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
13The following code is an example of creating a String reference:
.
String s;
True or false?

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 4 Lesson 4.
14The == operator can be used to compare two String objects. The result
. is always true if the two strings are have the exact same characters in
each position of the String. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct

Section 5
(Answer all questions in this section)
15How 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") ? "Mr." : "Ms." );
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
Correct

Mark for
Review
(1) Points

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 are relational operators in Java?

Mark for
Review
(1) Points

(Choose all correct answers)


< (*)
<= (*)
=
!= (*)
All of the above.
Correct
17. How would you use the ternary operator to rewrite this if
statement?
if (balance < 500)<
fee = 10;
else
fee = 0;

Mark for
Review
(1) Points

fee = ( balance < 500) ? 0 : 10;


fee= ( balance < 500) ? 10 : 0; (*)
fee = ( balance >= 5) ? 0 : 10;
fee = ( balance >= 500) ? 10 : 0;
fee = ( balance > 5) ? 10 : 0;
Incorrect. Refer to Section 5 Lesson 1.
18. One advantage to using a while loop over a for loop is that a
while loop always has a counter. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct

19. 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
20. When the for loop condition statement is met the construct is
exited. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct

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. Big-O Notation is used in Computer Science to describe the
performance of Sorts and Searches on arrays. True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
22. Which of the following best describes lexicographical order?

Mark for
Review
(1) Points

A simple sorting algorithm that is inefficient on large arrays.


An order based on the ASCII value of characters. (*)
A complex sorting algorithm that is efficient on large arrays.
The order of indicies after an array has been sorted.

Correct
23. 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
Correct
24. 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
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?

Mark for
Review
(1) Points

Because the parameters of the method were not met.


Because the interpreter does not recognize this method
since it was never initialized, the correct spelling of the
method was initialized.
Because the interpreter tries to read the method but when
it finds the method you intended to use it crashes.
This will not give you an exception, it will give you an error
when the program is compiled. (*)
Correct

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)

26What is the output of the following segment of code?


.

Mark for
Review
(1) Points

456789
777777 (*)
555555
987654
This code doesn't compile.
Correct
27Which of the following declares and initializes a two dimensional array
. that can hold 6 Object reference types?

Mark for
Review
(1) Points

String[] array=new String[6];


Object array=new Object[6];
Object[][] array=new Object[2][3]; (*)
String[][] array=String[6];
Correct
28The following segment of code initializes a 2 dimensional array of
. primitive data types. True or false?
double[][] a=new double[4][5];

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 6 Lesson 1.
29What is the output of the following segment of code?
.
int num[]={9,8,7,6,5,4,3,2,1};
for(int i=0;i<9;i=i+3)
System.out.print(num[i]);
9630
963 (*)
987654321
97531

Mark for
Review
(1) Points

This code doesn't compile.


Correct

Section 7
(Answer all questions in this section)
30Which of the following creates an object from the Animal class listed
. below:

Mark for
Review
(1) Points

Animal cat=new Animal();


Animal cat=Animal(50,30);
Animal cat=new Animal(50,30); (*)
Animal cat=new Animal(50);
Correct
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)
31What value will return for j when the setValue method is called?
.

Mark for
Review
(1) Points

31
32
10
11 (*)
Correct
32The basic unit of encapsulation in Java is the primitive data type. True
. or false?

Mark for
Review
(1) Points

True
False (*)
Correct
33What is wrong with the following class declaration?
.
class Account{ ;
private int number;
private String name;;
public Account;
}

Mark for
Review
(1) Points

Classes cannot include strings.


Classes cannot include mixed data types.
The constructor method has no definition. (*)
There is nothing wrong.
Correct
34Which 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();

Incorrect. Refer to Section 7 Lesson 1.


35A constructor is used to create objects. True or false?
.

Mark for
Review
(1) Points

True (*)
False
Correct
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 segment of code correctly defines a method that
contains two objects of class Tree as parameters?

Mark for Review


(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.
37. Which of the following could be a reason to return an object?

Mark for Review


(1) Points

Because you wish to be able to use that object inside of


the method.
It has faster performance than returning a primitive type.
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
38. Which of the following is the definition of a constructor?

Mark for Review


(1) Points

A keyword that specifies accessibility of code.

A special method that is used to assign initial values to


instance variables in a class. (*)
A way to call a method with a variable number of
arguments using an elipse.
A variable in a method declaration that gets passed into
the method.
Correct
39. Which of the following is the definition for a variable
argument method?

Mark for Review


(1) Points

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. (*)
Correct
40. Which of the following is the correct way to code a method
with a return type an object Automobile?

Mark for Review


(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
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. 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
42. Why are hierarchies useful for inheritance?

Mark for Review


(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. (*)
Incorrect. Refer to Section 7 Lesson 4.
43. An access modifier is a keyword that allows subclasses to
access methods, data, and constructors from their parent
class. True or false?

Mark for Review


(1) Points

True (*)
False
Correct
44. 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);
Incorrect. Refer to Section 7 Lesson 4.
45. Consider the following method of the class Test:
public static List returnList(List list)
{
return list;
}
Which of the following program segments in Test's client class
will compile with no errors?
I. List nums = new ArrayList();

Mark for Review


(1) Points

nums = Test.returnList(nums);
II. ArrayList nums = new ArrayList();
nums = Test.returnList(nums);
III. ArrayList nums1 = new ArrayList();
List nums2 = Test.returnList(nums1);

I only
I and III (*)
II only
II and III
I, II, and III
Correct
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. 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. (*)
Incorrect. Refer to Section 7 Lesson 5.
47. Would this code be correct if a Dog is a HousePet? Why or Why
not?
HousePet Scooby = new Dog();

Yes, because it is an abstract class.


Yes, because polymorphism allows this since Dog is a
subclass of HousePet. (*)
No, because ref must be declared either a HousePet or a
Dog, but not both.
Maybe. There is no way to tell without seeing the methods
for Dog and the methods for HousePet.
Correct

Mark for
Review
(1) Points

48. The base case condition can work with a constant or variable.
True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
49. Static methods can't change any class variable values at runtime. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct
50. Non-final static class variables should be private to prevent
changes from other classes. True or false?

Mark for
Review
(1) Points

True (*)
False
Correct

You might also like