1. Suppose that str1 and str2 are two strings. Which of the statement s or expression s are valid?
Mark for Review (1) Points
String str3 = str1 - str2;
str1 += str2; (*)
str1 >= str2
Str1 -= str2;
Incorrect. Refer to Section 4 Lesson 4.
2. The following program prints "Not Equal". True or false? Mark for
Review (1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
3. When a String object is created it must be assigned a value. True or false?
Mark for Review (1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 4.
4. Which of the following creates a String reference named s and instantiates it?
Mark for Review (1) Points
(Choose all correct answers)
String s=""; (*)
s="s";
String s;
String s=new String("s"); (*)
Incorrect. Refer to Section 4 Lesson 4.
5. What is printed by the following code segment? Mark for Review (1) Points
\\\\
\\\\\\\ (*)
\\\\\\\\\\\\\\
\\
Correct 6. Which line of Java code Mark for Review
properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers?
(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;
Incorrect. Refer to Section 4 Lesson 3.
7. What are Java's primitive types?
Mark for Review (1) Points
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short
Incorrect. Refer to Section 4 Lesson 3.
8. Which 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.
Incorrect. Refer to Section 4 Lesson 2.
9. The following defines a package 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.
10. A _______________ is used to organize Java related files.
Mark for Review (1) Points
Project
Workspace
Package (*)
Collection
Incorrect. Refer to Section 4 Lesson 1. 11. For every opening curly brace { there does not need to be a closing curly brace} for the program to compile without error. True or False? Mark for Review (1) Points
True
False (*)
Correct
12. You can return to the Eclipse Welcome Page by choosing Welcome from what menu? Mark for Review (1) Points
File
Edit
Help (*)
Close
Incorrect. Refer to Section 4 Lesson 1.
13. 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 (*)
Incorrect. Refer to Section 4 Lesson 1.
14. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review (1) Points
int
double (*)
boolean
None of the above
Correct
Section 5 (Answer all questions in this section)
15. How many times will the following loop be executed? What is the value of x after the loop has finished? What is the value of count after the loop has finished?
int count = 17; int x = 1; while(count > x){ x*=3; count-=3; }
Mark for Review (1) Points
4; 8; 27
3; 27; 8 (*)
5; 27; 8
5; 30; 5
3; 9; 11
Correct 16. Why are loops useful ? Mark for Review (1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of times.
They allow for repeating code until a certain argument is met.
All of the above. (*)
Incorrect. Refer to Section 5 Lesson 2.
17. 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; }
Mark for Review (1) Points
continue; (*)
break;
return;
k+=1;
Correct
18. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user's input and sets it equal to a new String called input?
Mark for Review (1) Points
String input = in.next(); (*)
String input = in.close();
String input = new String in.next();
String input = in.nextInt();
Incorrect. Refer to Section 5 Lesson 1.
19. The following prints Yes on the screen. True or false? Mark for Review (1) Points
True
False (*)
Correct
20. The six relational operators in Java are:
Mark for Review (1) Points
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
Correct 21. The followin g creates a referen ce in memory named q that Mark for Review (1) Points
can refer to six differen t integers via an index. True or false?
int[] q = new int[8];
True
False (*)
Correct
22. double 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 (*)
Incorrect. Refer to Section 6 Lesson 1.
23. The following creates a reference in memory named q that can refer to eight different doubles via an index. True or false? double[] q = new double[8];
Mark for Review (1) Points
True (*)
False
Correct
24. The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review (1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 1.
25. 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
Incorrect. Refer to Section 6 Lesson 2. 26. Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)? Mark for Review (1) Points
Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above
Correct
27. Binary searches can be performed on sorted and unsorted data. True or false?
Mark for Review (1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
28. Selection sort is efficient for large arrays. True or false?
Mark for Review (1) Points
True
False (*)
Correct
29. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review (1) Points
The next line of the program even if it is not the catch block of code.
Where the program catches the exception. (*)
The end of the program.
The user input.
Incorrect. Refer to Section 6 Lesson 3.
Section 7 (Answer all questions in this section)
30. 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.
Incorrect. Refer to Section 7 Lesson 2. 31. 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.
32. It is possible to overload a method that is not a constructor. True or False?
Mark for Review (1) Points
True (*)
False
Correct
33. 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
34. 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}
Incorrect. Refer to Section 7 Lesson 2.
35. What is true about the code below:
Car car1=new Car(); Car car2=new Car(); car2=car1;
Mark for Review (1) Points
(Choose all correct answers)
The references car1 and car2 are pointing to two Car Objects in memory.
The reference car2 points to an exact copy of the Car Object that car1 references. (*)
There are no more Car objects in memory.
There is a Car object that car1 referenced that is now slated for removal by the garbage collector.
There is a Car object that car2 referenced that is now slated for removal by the garbage collector. (*)
Incorrect. Refer to Section 7 Lesson 1. 36 . The following statement compiles and executes. What do you know for certain?
tree.grows(num Feet);
Mark for Review (1) Points
numFeet must be an int.
tree must be the name of the class.
grows must be the name of an instance field.
grows must be the name of a method. (*)
tree must be a method.
Incorrect. Refer to Section 7 Lesson 1.
37. The basic unit of encapsulation in Java is the primitive data type. True or false?
Mark for Review (1) Points
True
False (*)
Correct
38. The following code creates an object of type Animal. True or false? Animal a=new Animal();
Mark for Review (1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 1.
39. 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; }
Mark for Review (1) Points
1.75, 13
0.571, 21
1.75, 21
0.571, 13 (*)
Incorrect. Refer to Section 7 Lesson 1.
40. Which 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);
Incorrect. Refer to Section 7 Lesson 1. 41. 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
42. Static methods can't act like "setter" methods. True or false?
Mark for Review (1) Points
True
False (*)
Correct
43. Any instance of the same class can assign a new value to a static variable. True or false? Mark for Review (1) Points
True (*)
False
Correct
44. According to the following class declaration, runSpeed can be modified in class Cat. True or false?
public class Tiger extends Cat{ public int runSpeed; }
Mark for Review (1) Points
True
False (*)
Correct
45. 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 4 6 . Consider creating a class Square that extends the Rectangle class provided below. Knowing that a square always has the same width and length, which of the following best represents a constructor for the Square class? Mar k for Review (1) Points
(*) None of the above.
Correct
47. What is encapsulation?
Mar k 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. 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. (*)
Incorrect. Refer to Section 7 Lesson 4.
48. If Oak extends Tree, it is possible to declare an object such that
Tree grandfatherT = new Oak(); True or false?
Mar k for Review (1) Points
True (*) False
Correct
49. Identify the step(s) in creating a Triangle Applet that displays two triangles. Mar k for Review (1) Points
(Choose all correct answers)
Extend Applet class to inherit all methods including paint. (*) Override the paint method to include the triangles. (*) Draw the triangle using the inherited fillPolygon method. (*) Draw the 2nd triangle using the inherited fillPolygon method. (*) Run and compile your code. (*) None of the above.
Incorrect. Refer to Section 7 Lesson 5.
50. What does it mean to override a method?
Mar k 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. (*)

Tidak ada komentar:
Posting Komentar