Date post: | 22-Dec-2015 |
Category: |
Documents |
Upload: | kurodokoljenko |
View: | 226 times |
Download: | 2 times |
(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?
Mark for
Review (1) Points
True
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)
11.
The 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
12.
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.
Correct
13.
What 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
14.
Examine the following code:
What is the value of variable x?
Mark for
Review (1) Points
2 (*)
2.5
6
14
Correct
Section 5
(Answer all questions in this section)
15.
When 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)
21.
What will be the content of the array variable table after executing the following code? Mark for
Review (1) Points
1 1 10 1 10 0 11 0 00 1 00 0 11 0 01 1 01 1 1 (*)0 0 10 1 01 0 0
Incorrect. Refer to Section 6 Lesson 1.
22.
What will array arr contain after the following code segment has been executed?
int [] arr = {5, 4, 2, 1, 0};for (int i = 1; i < arr.length; i++)<br> {arr[i - 1] += arr[i];}
Mark for
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.
23.
Which 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.
24.
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 (*)
Correct
25.
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
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)
36.
Static methods can read instance variables. True or false? Mark for
Review (1) Points
True
False (*)
Correct
37.
Identify 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
38.
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.
39.
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
40.
Which 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)
41.
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
42.
A class always has a constructor. True or false? Mark for
Review (1) Points
True (*)
False
Correct
43.
The basic unit of encapsulation in Java is the primitive data type. True or false? Mark for
Review (1) Points
True
False (*)
Correct
44.
Which 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.
45.
In 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)
46.
The following code creates an object of type Animal. True or false?
Animal a=new Animal(); Mark for
Review (1) Points
True (*)
False
Correct
47.
Consider:
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.
48.
Identify 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
49.
If 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.
50.
If 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 42It 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 0It would print the string returned from the method. The console screen would display: {0, 18, 215, 64, 11, 42}
Correct