You are on page 1of 16

(Answer all questions in this section)

1.The following code prints 5 "a"'s to the screen:

Mark for
Review
(1) Points

True
False (*)
Correct
2.Suppose that str1 and str2 are two strings. Which of the statements or
expressions are valid?

Mark for
Review
(1) Points

String str3 = str1 - str2;


str1 += str2; (*)
str1 >= str2
Str1 -= str2;
Correct
3.Which of the following instantiates a String named name to Oracle?

Mark for
Review
(1) Points

String name;
String Oracle="name";
String name="name";
String name="Oracle"; (*)
Correct
4.The == 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?

True

Mark for
Review
(1) Points

False (*)
Correct
5.What is printed by the following code segment?

Mark for
Review
(1) Points

\\\\
\\\\\\\ (*)
\\\\\\\\\\\\\\
\\
(Answer all questions in this section)
6. You need to _______________ Java code to generate a .class file

Mark for
Review
(1) Points

Collect
Compile (*)
Package
Assemble
Correct
7. When you open more than one file in Eclipse the system will
__________________.

Mark for
Review
(1) Points

Close the previously opened file.


Use tabs to display all files open. (*)
Put the new file opened in a View area only.
None of the above.
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 (*)
Correct
9. What is the purpose of the Eclipse Editor Area and Views?

Mark for
Review
(1) Points

(Choose all correct answers)


To modify elements. (*)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
Correct
10. A workspace can not have more than one stored projects. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct
(Answer all questions in this section)
11The 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
12Which 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
13What is the output of the following lines of code?
.
int j=6,k=4,m=12,result;
result=j/m*k;
System.out.println(result);

Mark for
Review
(1) Points

2
0 (*)
48
24
Correct
14Examine the following code:
.

Mark for
Review
(1) Points

What is the value of variable x?


2 (*)
2.5
6
14
Correct

Section 5
(Answer all questions in this section)

15When the for loop condition statement is met the construct is exited. True or
. false?

Mark for
Review
(1) Points

True
False (*)
Correct
(Answer all questions in this section)
16. In a for loop the counter is not automatically incremented after each loop
iteration. Code must be written to increment the counter. True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
17. 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
18. The three logic operators in Java are:

Mark for
Review
(1) Points

&&, ||, ! (*)


!=,=,==
&&,!=,=
&,|,=
Correct

19. What will print if the following Java code is executed?


if ((5.1 > 4.3 && 6.2 < 8.4) && !(7.2 < 3.5 || 1.2 == 2.1 || 2.2 != 2.25)) <
System.out.print("TRUE"); else
System.out.print("FALSE");

Mark for
Review
(1) Points

True
False (*)
Incorrect. Refer to Section 5 Lesson 1.
20. 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
(Answer all questions in this section)
21What will be the content of the array variable table after executing the following
. code?

Mark for
Review
(1) Points

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.


22What will array arr contain after the following code segment has been
. executed?

Mark for

int [] arr = {5, 4, 2, 1, 0};


for (int i = 1; i < arr.length; i++)<br> {
arr[i - 1] += arr[i];
}

Review
(1) Points

9, 6, 1, 3, 0
10, 6, 3, 1, 0
9, 6, 3, 1, 0 (*)
7, 3, 2, 1, 0
None of the above.
Incorrect. Refer to Section 6 Lesson 1.
23Which of the following declares and initializes a two dimensional array with 3
. rows and 2 columns?

Mark for
Review
(1) Points

int a={{1,1},{1,1},{1,1}};
int[][] a={{1,1},{1,1},{1,1}}; (*)
int[][] a={{1,1,1},{1,1,1}};
int a={{1,1,1},{1,1,1}};
Incorrect. Refer to Section 6 Lesson 1.
24double array[] = new double[8];
.
After execution of this statement, which of the following are true?

Mark for
Review
(1) Points

array[0] is undefined
array[4] is null
array[2] is 8
array.length is 8 (*)
Correct
25Selection 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?

True (*)
False

Mark for
Review
(1) Points

Incorrect. Refer to Section 6 Lesson 2.


(Answer all questions in this section)
26. Of the options below, what is the fastest run-time?

Mark for
Review
(1) Points

n
n^2
lg(n) (*)
n*lg(n)
Correct
27. 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 on until the array is sorted. True or false?

Mark for
Review
(1) Points

True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
28. Why might a sequential search be inefficient?

Mark for
Review
(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm
more error prone.
It requires incrementing through the entire array in the worst case,
which is inefficient on large data sets. (*)
It involves looping through the array multiple times before finding the
value, which is inefficient on large data sets.
It is never inefficient.
Incorrect. Refer to Section 6 Lesson 2.
29. What are exceptions used for in Java?

Mark for
Review
(1) Points

Correcting mistakes made in your code and handling extraordinary


cases. (*)

Exceptions have no use, they are just a part of the Java language.
Helping the interpreter compile code quicker and handle user
interfaces.
Making the program easier to use for the user and reducing the
possibilities of errors occuring.
Correct

Section 7
(Answer all questions in this section)
30. Which of the following show the correct UML representation of the super
class Planet and its subclass Earth?

Mark for
Review
(1) Points

(*)

None of the above.


Incorrect. Refer to Section 7 Lesson 4.
(Answer all questions in this section)

31. 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.
A keyword that allows access from anywhere.
Correct
32. If you inherit a class, you do not inherit the class' constructors. True or
false?

Mark for
Review
(1) Points

True (*)
False
Correct
33. 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. (*)
Correct
34. Static classes are designed as thread safe class instances. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct

35. Which of the following access modifiers doesn't work with a static variable?

Mark for
Review
(1) Points

public
protected
friendly (*)
default
private
Correct
(Answer all questions in this section)
36Static methods can read instance variables. True or false?
.

Mark for
Review
(1) Points

True
False (*)
Correct
37Identify the error(s) in the class below. Choose all that apply.
.

Mark for
Review
(1) Points

(Choose all correct answers)


No method named min is defined. (*)
Two methods cannot have the same name.
The parameters must be the same for all methods with the same name.
Private cannot be used as an access modifier.
Final cannot be used as an access modifier.
Correct
38It is possible to return an object from a method. True or false?
.

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 7 Lesson 2.
39Which 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
40Which 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.
(Answer all questions in this section)
41Which 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
42A class always has a constructor. True or false?
.

Mark for
Review
(1) Points

True (*)
False
Correct
43The basic unit of encapsulation in Java is the primitive data type. True or false?
.

Mark for
Review
(1) Points

True
False (*)
Correct
44Which of the following creates a method that compiles with no errors in the
. class?

Mark for
Review
(1) Points

(*)

All of the above.


None of the above.
Incorrect. Refer to Section 7 Lesson 1.
45In Java, an instance field referenced using the this keyword generates a
. compilation error. True or false?

Mark for
Review

(1) Points
True
False (*)
Correct
(Answer all questions in this section)
46The following code creates an object of type Animal. True or false?
.
Animal a=new Animal();

Mark for
Review
(1) Points

True (*)
False
Correct
47Consider:
.
public class YourClass{ public YourClass(int i){/*code*/} // more code...}
To instantiate YourClass, what would you write?

Mark for
Review
(1) Points

YourClass y = new YourClass();


YourClass y = new YourClass(3); (*)
YourClass y = YourClass(3);
YourClass y = YourClass();
None of the above.
Incorrect. Refer to Section 7 Lesson 1.
48Identify the correct way to declare an abstract class.
.

Mark for
Review
(1) Points

abstract public class ClassName{...}


public abstract ClassName(...)
public class abstract ClassName(...)
public abstract class ClassName{...} (*)
Correct

49If a class is immutable then it must be abstract. True or false?


.

Mark for
Review
(1) Points

True
False (*)
Incorrect. Refer to Section 7 Lesson 5.
50If we override the toString() method with the code below, what would be the
. result of printing?

Mark for
Review
(1) Points

It would print the array one element at a time. The console screen would
display: 0 18 215 64 11 42
It would print the string returned from the method. The console screen
would display: [0,18,215,64,11,42,] (*)
It would print the array backwards. The console screen would display: 42 11
64 215 18 0
It would print the string returned from the method. The console screen
would display: {0, 18, 215, 64, 11, 42}
Correct

You might also like