Sie sind auf Seite 1von 15

arief

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

char, int, double, long, String (*)


boolean, byte, int, long, Short
char, int, long, float, String
char, boolean, float, long, String
char, double, int, long, String
Correct
7. Which line of Java code properly calculates the area of a triangle using
A=1/2(b)(h) where b and h are Java primitive integers?

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

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


.

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

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)
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

(Choose all correct answers)


< (*)
<= (*)
=
!= (*)
All of the above.
Correct
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.");

Mark for
Review
(1) Points

System.out.print( (gender == "female") ? "Mr." : "Ms." );


System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
(gender == "female") ? "Mr." : "Ms." ;
(gender == "female") ? "Ms." : "Mr." ;
Correct
18. What should replace the comment "//your answer here" in the code below if
the code is meant to take no action when i % 2 is 0 (in other words when i is
even)?
for(int i = 0; i < 10; i++){<br> if(i%2 == 0)
//your answer here
else
k+=3;
}
continue; (*)

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

After execution of this statement, which of the following are true?


Review
(1) Points
array[0] is undefined
array[4] is null
array[2] is 8
array.length is 8 (*)
Correct
Section 6
(Answer all questions in this section)

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

int[] y = new int[5];


Review
(1) Points
True (*)
False
Correct
28. Which of the following statements add all of the elements of the one
dimensional array prices, and then prints the sum to the screen?

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

39Which 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
40If the return type from a method is boolean then 2.5 is a valid return value. True
. or false?

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

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();

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

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
45What 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.

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

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
47. Which segment of code represents a correct way to define a variable
argument method?

Mark for
Review
(1) Points

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


String easyArray(... String elems) {//code}
String ... easyArray(String elems) {//code}
Integer easyArray ... (int elems) {//code}
Correct
48. How is it possible for overloading to work?

Mark for
Review
(1) Points

There is no such thing as overloading.


The code has to be declared as private.

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

(Choose all correct answers)


Integers (*)
Strings (*)
Constructors
Arrays (*)
Objects (*)
Incorrect. Refer to Section 7 Lesson 2.

Das könnte Ihnen auch gefallen