Professional Documents
Culture Documents
Section 4
(Answer all questions in this section)
1. What symbols are required for a compiler to ignore a comment?
Mark for
Review
(1) Points
// (*)
/*
*/
/*/
Correct
2. In a project, 1 of the classes must contain a main method. True or False?
Mark for
Review
(1) Points
True (*)
False
Correct
3. Eclipse does not provide views to help you navigate a hierarchy of
information. True or False?
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.
4. Four variables are required to support a conversion of one unit of measure to
another unit of measure. True or False?
Mark for
Review
(1) Points
True
False (*)
Correct
arief
5. In Eclipse, when you run a Java Application, where may the results display?
Mark for
Review
(1) Points
Editor Window
Console View (*)
Debug View
Task List
None of the above
Correct
Section 4
(Answer all questions in this section)
6. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its
respective data type.
Mark for
Review
(1) Points
Mark for
Review
(1) Points
double A=1/2*b*h;
double A=1/2bh;
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
Correct
8. 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?
Mark for
Review
arief
(1) Points
True
False (*)
Correct
9. 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
10. 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
Section 4
(Answer all questions in this section)
11Consider the following code snippet
.
String forest = new String("Black");
System.out.println(forest.length());
What is printed?
5 (*)
6
7
Black
Forest
Correct
Mark for
Review
(1) Points
arief
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
13The following defines a class 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. (*)
Incorrect. Refer to Section 4 Lesson 2.
14Which of the following defines an object class?
.
Mark for
Review
(1) Points
Section 5
(Answer all questions in this section)
15Determine whether this boolean expression evaluates to true or false:
.
!(3<4&&6>6||6<=6&&7-2==6)
Mark for
Review
arief
(1) Points
True (*)
False
Incorrect. Refer to Section 5 Lesson 1.
Section 5
(Answer all questions in this section)
16. Which of the following are relational operators in Java?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
arief
break;
return;
k+=1;
Correct
19. 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
20. When the for loop condition statement is met the construct is exited. True
or false?
Mark for
Review
(1) Points
True
False (*)
Correct
Section 6
(Answer all questions in this section)
21. 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.
Correct
arief
22. 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
23. 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
24. Selection 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?
Mark for
Review
(1) Points
True (*)
False
Correct
25. double array[] = new double[8];
Mark for
arief
26. The 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
Correct
27. The following array declaration is valid. True or false?
Mark for
Mark for
Review
(1) Points
int total = 0;
for(int i = 0; i
total+=prices[i];
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(total); (*)
int total = 0;
for(int i = 1; i
total = total+prices[i];
System.out.println(prices);
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(prices);
Correct
29. Suppose you are writing a program where the user is prompted to the give
coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If
the princess is not found at those coordinates, the user is given a clue that
helps them guess coordinates closer to the princess. The user is allowed to
enter their new guess of where the princess is.
Mark for
Review
(1) Points
arief
Assume your program does not take into consideration the possibility that
the user may enter coordinates outside of the castle where the princess
could not be. What would be the result of the user entering coordinates
outside of the castle? How could this be handled in your code?
(Choose all correct answers)
An error would occur. Errors cannot be handled by code.
An exception would occur but could not be handled inside your code.
The user would have to restart the program and enter proper
coordinates.
An exception would occur. This could be handled by throwing the
exception in your code if the user enters invalid coordinates. When the
exception is caught, the prince could be moved to the coordinate
inside the castle that is closest to those that the user specified. (*)
An exception would occur. This could be handled by throwing an
exception in your code if the user enters invalid coordinates. When the
exception is caught, the user could be prompted to enter coordinates
within the given range of the castle. (*)
Incorrect. Refer to Section 6 Lesson 3.
Section 7
(Answer all questions in this section)
30. A static variable is always publicly available. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
Section 7
(Answer all questions in this section)
31. A linear recursive method directly calls how many copies of itself in the
recursive case?
Mark for
Review
(1) Points
0
1 (*)
2 or more
Correct
arief
32. Public static variables can't have their value reset by other classes. True or
false?
Mark for
Review
(1) Points
True
False (*)
Correct
33. If a class is immutable then it must be abstract. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
34. Which of the following can be declared final?
Mark for
Review
(1) Points
Classes
Methods
Local variables
Method parameters
All of the above (*)
Correct
35. 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();
nums = Test.returnList(nums);
II. ArrayList nums = new ArrayList();
Mark for
Review
(1) Points
arief
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
Section 7
(Answer all questions in this section)
36A class can only have one constructor. True or false?
.
Mark for
Review
(1) Points
True
False (*)
Correct
37The following code creates an object of type Animal. True or false?
.
Animal a=new Animal();
Mark for
Review
(1) Points
True (*)
False
Correct
38What operator do you use to call an object's constructor method and create a
. new object?
Mark for
Review
(1) Points
+
new (*)
instanceOf
Correct
arief
Mark for
Review
(1) Points
Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 1.
Section 7
(Answer all questions in this section)
41Which of the following calls the method calculate correctly?
.
Mark for
Review
(1) Points
arief
Correct
42If a variable in a superclass is private, could it be directly accessed or modified
. by a subclass? Why or why not?
Mark for
Review
(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
43It is possible for a subclass to be a superclass. True or false?
.
Mark for
Review
(1) Points
True (*)
False
Correct
44Why are hierarchies useful for inheritance?
.
Mark for
Review
(1) Points
Mark for
Review
(1) Points
arief
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
Section 7
(Answer all questions in this section)
46. Which of the following is the correct way to code a method with a return
type an object Automobile?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
Mark for
Review
(1) Points
arief
The interpreter doesn't care what you name your constructors.
Java Virtual Machine searches until it finds a constructor name and
argument type match. (*)
Correct
49. It 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.
50. Which of the following can be used as a parameter?
Mark for
Review
(1) Points