Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
Incorrect Incorrect. Refer to Section 3 Lesson 3.
2. Forward thinking helps when creating linear recursive methods.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 3 Lesson 3.
3. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
Incorrect Incorrect. Refer to Section 3 Lesson 3.
4. Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?
public static int recur(int x, int y) {
if (x == 0) {
return y;
}
return recur(x - 1, x + y);
} Mark for Review
(1) Points
12
10
9
13 (*)
Incorrect Incorrect. Refer to Section 3 Lesson 3.
5. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
indexOf(String str)
charAt(int index)
delete(int start, int end) (*)
length()
What class is the split() method a member of? Mark for Review
(1) Points
String (*)
Parse
StringBuilder
Array
Incorrect Incorrect. Refer to Section 3 Lesson 1.
7. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Search for a specific character or String inside of the String. (*)
Read the String backwards (from last element to first element). (*)
Parse the String. (*)
You don't use a FOR loop with Strings
Incorrect Incorrect. Refer to Section 3 Lesson 1.
8. What is the result from the following code?
public class Test {
public static void main(String[] args) {
String str = "91204";
str += 23;
System.out.print(str);
}
} Mark for Review
(1) Points
9120423 (*)
23
Compile fails.
91227
91204
Incorrect Incorrect. Refer to Section 3 Lesson 1.
9. Which of the following does not correctly match the regular expression symbol to its proper function? Mark for Review
(1) Points
"{x}" means there must be x occurrences of the preceding character in the string to be a match.
"?" means there may be zero or one occurrences of the preceding character in the string to be a match.
"+" means there may be zero or more occurrences of the preceding character in the string to be a match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a match.
"{x,y}" means there may be between x and y occurrences of the preceding character in the string to be a match.
Incorrect Incorrect. Refer to Section 3 Lesson 2.
10. Which of the following methods for the String class take a regular expression as a parameter and returns true if the string matches the expression? Mark for Review
(1) Points
matches(String regex) (*)
compareTo(String regex)
equalsIgnoreCase(String regex)
equals(String regex)
Incorrect Incorrect. Refer to Section 3 Lesson 2.
Consider that you are writing a program for analyzing feedback on the video game you have developed. You have completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the user's input is a valid rating?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("{1-5}");
return userI.matches("[1-5]{1}"); (*)
return userI.matches("[1-5].*");
return userI.matches("[1-5]"); (*)
Incorrect Incorrect. Refer to Section 3 Lesson 2.
12. Which of the following correctly defines Pattern? Mark for Review
(1) Points
A regular expression symbol that represents any character.
A class in the java.util.regex package that stores matches.
A method of dividing a string into a set of sub-strings.
A class in the java.util.regex package that stores the format of a regular expression. (*)
Correct Correct
13. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review
(1) Points
Matcher m = p.matcher(str); (*)
Matcher m = new Matcher(p,str);
Matcher m = str.matcher(p);
Matcher m = new Matcher();
Incorrect Incorrect. Refer to Section 3 Lesson 2.
14. Which of the following correctly defines a repetition operator? Mark for Review
(1) Points
A symbol that represents any character in regular expressions.
A method that returns the number of occurrences of the specified character.
symbol in regular expressions that indicates the number of occurrences a specified character appears in a matching string. (*)
None of the above.
Correct Correct
15. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may occur x or more times to create a match.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
Senin, 08 Mei 2017
OJP 2
1. What is the output from the following code snippet?
String str1= "java";
String str2=new String("java");
System.out.println( str1==str2 );
System.out.println( str1==str2.intern() );
Mark for Review
(1) Points
The code will compile and print "false false"
The code will compile and print "true true"
The code does not compile.
The code will compile and print "false true" (*)
The code will compile and print "true false"
Incorrect incorrect. Refer to Section 1 Lesson 1.
2. Examine the following Classes:
Student and TestStudent
What is the output from the println statement in TestStudent?
public class Student {
private int studentId = 0;
public Student(){
studentId++;
}
public static int getStudentId(){
return studentId;
}
}
public class TestStudent {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
System.out.println(Student.getStudentId());
}
} Mark for Review
(1) Points
1
3
TestStudent will throw an exception
No output. Compilation of TestStudent fails (*)
Incorrect incorrect. Refer to Section 1 Lesson 1.
3. What is the output from the following code snippet?
for (int i = 0; i < 10; i++) {
if (i == 3) {
break;
}
System.out.print(i); Mark for Review
(1) Points
The code will compile and print "123"
The code will compile and print "012" (*)
The code will compile and print "0123"
The code does not compile.
Correct Correct
4. What do Arrays and ArrayLists have in common?
I. They both store data.
II. They can both be traversed in loops.
III. They both can be dynamically re-sized during execution of a program.
Mark for Review
(1) Points
I only
II only
I and II only (*)
I, II and III only
None of these
Correct Correct
5. When an object is able to pass on its state and behaviors to its children, this is called: Mark for Review
(1) Points
Isolation
Encapsulation
Polymorphism
Inheritance (*)
Correct Correct
6. Which of the following statements is false? Mark for Review
(1) Points
In an Array you need to know the length and the current number of elements stored.
An ArrayList can grow and shrink dynamically as required.
An ArrayList has a fixed length. (*)
An ArrayList can store multiple object types.
Incorrect Incorrect. Refer to Section 1 Lesson 2.
7. Reading great code is just as important for a programmer as reading great books is for a writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Examine the following code snippet. What is this an example of?
public class Car extends Vehicle {
public Car() {
...
}
} Mark for Review
(1) Points
Inheritance (*)
Polymorphism
Comments
Encapsulation
Correct Correct
9. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 2
(Answer all questions in this section)
10. public static void printArray(T[] array){οΎ….
is an example of what? Mark for Review
(1) Points
A generic instance
A generic method (*)
A generic class
A concreate method.
Incorrect Incorrect. Refer to Section 2 Lesson 3.
11. An example of an upper bounded wildcard is. Mark for Review
(1) Points
ArrayList<T>
ArrayList<? extends Animal> (*)
ArrayList<?>
ArrayList<? super Animal>
Correct Correct
12. Wildcards in generics allows us greater control on the types that can be used.
True or False? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 3.
13. When would an enum (or enumeration) be used? Mark for Review
(1) Points
When you already know all the possibilities for objects of that class. (*)
When you want to be able to create any number of objects of that class.
When you wish to initialize a HashSet.
When you wish to remove data from memory.
Correct Correct
14. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
log(n) (*)
n
n^2
n*log(n)
Correct Correct
15. 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 Correct
16. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
Correct Correct
17. Binary searches can be performed on sorted and unsorted data.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 6.
18. 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 Correct
19. Selection sort is efficient for large arrays.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
20. 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 (*)
Correct Correct
21. A sequential 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 Correct
22. A LinkedList is a type of Stack.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
23. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Because you can not add element to the beginning of it.
Because you can remove elements from the end of it. (*)
Because you can add elements to the end of it. (*)
Because you can remove elements from the beginning of it. (*)
Correct Correct
24. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
25. FIFO stands for: Mark for Review
(1) Points
Fast In Fast Out
First In First Out (*)
Fast Interface Fast Output
First Interface First Output
Correct Correct
26. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
27. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points
Enums
Stacks (*)
HashMaps
Arrays
Correct Correct
28. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Correct Correct
29. What are maps that link a Key to a Value? Mark for Review
(1) Points
ArrayLists
Arrays
HashMaps (*)
HashSets
Correct Correct
30. A downward cast of a superclass to subclass allows you to access a subclass specialized method call.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
31. What is the result of the following code snippet??
1. abstract class AbstractBankAccount {
2. abstract int getBalance ();
3. )
4. public class CreditAccount extends AbstractBankAccount{
5. private int balance;
6. private int getBalance (){
7. return balance;
8. }
9.} Mark for Review
(1) Points
Compilation is successful.
An error at line 6 causes compilation to fail. (*)
An error at line 2 causes compilation to fail.
An error at line 4 causes compilation to fail.
Correct Correct
32. Virtual method invocation requires that the superclass method is defined as which of the following? Mark for Review
(1) Points
A default final method.
A public method. (*)
A private final method.
A public static method.
A public final method.
Correct Correct
33. When line 10 is executed, which method will be called?
1 class Account {
2 public void deposit(int amt, int amt1) { }
3 public void deposit(int amt){ }
4 }
5 public class CreditAccount extends Account {
6 public void deposit() { }
7 public void deposit(int amt) {}
8 public static void main(String args[]){
9 Account account = new CreditAccount();
10 account.deposit(10);
11 }
12 } Mark for Review
(1) Points
line 6
line 7 (*)
line 2
line 3
Correct Correct
34. Upward casting an object instance means you can't access subclass specific methods.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
35. Which two of the following statements are true? (Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
An abstract class can create subclass and be constructed.
An abstract class can define constructor. (*)
An abstract class must be difined by using the abstract keyword. (*)
An abstract class must contain abstrct method.
Correct Correct
36. Which line contains an compilation error?
interface Shape {}
interface InnerShape extends Shape{}
class Circle implements Shape{ }
class InnerCircle extends Circle{}
class Rectangle implements Shape{}
public class Tester {
public static void main(String[] args) {
Circle c= new Circle();
InnerCircle ic = new InnerCircle();
Rectangle rect = new Rectangle();
System.out.print(c instanceof InnerCircle); //Line 1
System.out.print(ic instanceof Circle); //Line 2
System.out.print(rect instanceof InnerCircle); //Line 3
System.out.print(rect instanceof Shape); //Line 4
}
} Mark for Review
(1) Points
Line 1
Line 4
Line 2
Line 3 (*)
Correct Correct
37. Which of the following statements can be compiled?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
List list = new ArrayList<String>(); (*)
List<String> list = new ArrayList<String>(); (*)
List<?> list = new ArrayList<String>(); (*)
List<Object> list = new ArrayList<String>();
Incorrect Incorrect. Refer to Section 2 Lesson 4.
38. What is the output from the following code snippet?
Integer[] ar = {1, 2, 1, 3};
Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));
set.add(4);
for (Integer element : set) {
System.out.print(element);
} Mark for Review
(1) Points
11234
12134
1234 (*)
1213
Correct Correct
39. A collection is an interface in the Java API.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
40. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
41. Which class is an ordered collection that may contain duplicates? Mark for Review
(1) Points
array
set
enum
list (*)
Correct Correct
42. What is a set? Mark for Review
(1) Points
A collection of elements that does not contain duplicates. (*)
A keyword in Java that initializes an ArrayList.
A collection of elements that contains duplicates.
Something that enables you to create a generic class without specifying a type between angle brackets <>.
Correct Correct
43. Which line contains a compilation error?
interface Shape {}
class Circle implements Shape{}
public class Test{
public static void main(String[] args) {
List<? extends Shape> ls = new ArrayList<Circle>(); // Line 1
List<Circle> lc = new ArrayList<Circle>(); // Line 2
Circle c = new Circle();
ls.add(c); // Line 3
lc.add(c); // Line 4
}
} Mark for Review
(1) Points
Line 4
Line 1
Line 2
Line 3 (*)
Correct Correct
44. You can only implement one interface in a class.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
45. Classes define and implement what? Mark for Review
(1) Points
Some methods with implementations
All methods with implementations
Variables and methods (*)
All method definitions without any implementations
Constants and all methods with implementations
Correct Correct
46. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points
True (*)
False
Correct Correct
47. Which one of the following would allow you to define an interface for Animal? Mark for Review
(1) Points
public Animal extends Interface {}
public interface Animal {} (*)
public class Animal implements Interface {}
public class Animal {}
Correct Correct
48. The state of an object differentiates it from other objects of the same class.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
49. Which one of the following statements is true? Mark for Review
(1) Points
A class is a template that defines the features of an object (*)
A class is a Java primitive
A Java program can only contain one super class
A class is an intance of an object
Correct Correct
50. Immutable classes do allow instance variables to be changed by overriding methods.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
String str1= "java";
String str2=new String("java");
System.out.println( str1==str2 );
System.out.println( str1==str2.intern() );
Mark for Review
(1) Points
The code will compile and print "false false"
The code will compile and print "true true"
The code does not compile.
The code will compile and print "false true" (*)
The code will compile and print "true false"
Incorrect incorrect. Refer to Section 1 Lesson 1.
2. Examine the following Classes:
Student and TestStudent
What is the output from the println statement in TestStudent?
public class Student {
private int studentId = 0;
public Student(){
studentId++;
}
public static int getStudentId(){
return studentId;
}
}
public class TestStudent {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
System.out.println(Student.getStudentId());
}
} Mark for Review
(1) Points
1
3
TestStudent will throw an exception
No output. Compilation of TestStudent fails (*)
Incorrect incorrect. Refer to Section 1 Lesson 1.
3. What is the output from the following code snippet?
for (int i = 0; i < 10; i++) {
if (i == 3) {
break;
}
System.out.print(i); Mark for Review
(1) Points
The code will compile and print "123"
The code will compile and print "012" (*)
The code will compile and print "0123"
The code does not compile.
Correct Correct
4. What do Arrays and ArrayLists have in common?
I. They both store data.
II. They can both be traversed in loops.
III. They both can be dynamically re-sized during execution of a program.
Mark for Review
(1) Points
I only
II only
I and II only (*)
I, II and III only
None of these
Correct Correct
5. When an object is able to pass on its state and behaviors to its children, this is called: Mark for Review
(1) Points
Isolation
Encapsulation
Polymorphism
Inheritance (*)
Correct Correct
6. Which of the following statements is false? Mark for Review
(1) Points
In an Array you need to know the length and the current number of elements stored.
An ArrayList can grow and shrink dynamically as required.
An ArrayList has a fixed length. (*)
An ArrayList can store multiple object types.
Incorrect Incorrect. Refer to Section 1 Lesson 2.
7. Reading great code is just as important for a programmer as reading great books is for a writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Examine the following code snippet. What is this an example of?
public class Car extends Vehicle {
public Car() {
...
}
} Mark for Review
(1) Points
Inheritance (*)
Polymorphism
Comments
Encapsulation
Correct Correct
9. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 2
(Answer all questions in this section)
10. public static void printArray(T[] array){οΎ….
is an example of what? Mark for Review
(1) Points
A generic instance
A generic method (*)
A generic class
A concreate method.
Incorrect Incorrect. Refer to Section 2 Lesson 3.
11. An example of an upper bounded wildcard is. Mark for Review
(1) Points
ArrayList<T>
ArrayList<? extends Animal> (*)
ArrayList<?>
ArrayList<? super Animal>
Correct Correct
12. Wildcards in generics allows us greater control on the types that can be used.
True or False? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 3.
13. When would an enum (or enumeration) be used? Mark for Review
(1) Points
When you already know all the possibilities for objects of that class. (*)
When you want to be able to create any number of objects of that class.
When you wish to initialize a HashSet.
When you wish to remove data from memory.
Correct Correct
14. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
log(n) (*)
n
n^2
n*log(n)
Correct Correct
15. 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 Correct
16. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
Correct Correct
17. Binary searches can be performed on sorted and unsorted data.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 6.
18. 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 Correct
19. Selection sort is efficient for large arrays.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
20. 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 (*)
Correct Correct
21. A sequential 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 Correct
22. A LinkedList is a type of Stack.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
23. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Because you can not add element to the beginning of it.
Because you can remove elements from the end of it. (*)
Because you can add elements to the end of it. (*)
Because you can remove elements from the beginning of it. (*)
Correct Correct
24. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
25. FIFO stands for: Mark for Review
(1) Points
Fast In Fast Out
First In First Out (*)
Fast Interface Fast Output
First Interface First Output
Correct Correct
26. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
27. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points
Enums
Stacks (*)
HashMaps
Arrays
Correct Correct
28. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Correct Correct
29. What are maps that link a Key to a Value? Mark for Review
(1) Points
ArrayLists
Arrays
HashMaps (*)
HashSets
Correct Correct
30. A downward cast of a superclass to subclass allows you to access a subclass specialized method call.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
31. What is the result of the following code snippet??
1. abstract class AbstractBankAccount {
2. abstract int getBalance ();
3. )
4. public class CreditAccount extends AbstractBankAccount{
5. private int balance;
6. private int getBalance (){
7. return balance;
8. }
9.} Mark for Review
(1) Points
Compilation is successful.
An error at line 6 causes compilation to fail. (*)
An error at line 2 causes compilation to fail.
An error at line 4 causes compilation to fail.
Correct Correct
32. Virtual method invocation requires that the superclass method is defined as which of the following? Mark for Review
(1) Points
A default final method.
A public method. (*)
A private final method.
A public static method.
A public final method.
Correct Correct
33. When line 10 is executed, which method will be called?
1 class Account {
2 public void deposit(int amt, int amt1) { }
3 public void deposit(int amt){ }
4 }
5 public class CreditAccount extends Account {
6 public void deposit() { }
7 public void deposit(int amt) {}
8 public static void main(String args[]){
9 Account account = new CreditAccount();
10 account.deposit(10);
11 }
12 } Mark for Review
(1) Points
line 6
line 7 (*)
line 2
line 3
Correct Correct
34. Upward casting an object instance means you can't access subclass specific methods.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
35. Which two of the following statements are true? (Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
An abstract class can create subclass and be constructed.
An abstract class can define constructor. (*)
An abstract class must be difined by using the abstract keyword. (*)
An abstract class must contain abstrct method.
Correct Correct
36. Which line contains an compilation error?
interface Shape {}
interface InnerShape extends Shape{}
class Circle implements Shape{ }
class InnerCircle extends Circle{}
class Rectangle implements Shape{}
public class Tester {
public static void main(String[] args) {
Circle c= new Circle();
InnerCircle ic = new InnerCircle();
Rectangle rect = new Rectangle();
System.out.print(c instanceof InnerCircle); //Line 1
System.out.print(ic instanceof Circle); //Line 2
System.out.print(rect instanceof InnerCircle); //Line 3
System.out.print(rect instanceof Shape); //Line 4
}
} Mark for Review
(1) Points
Line 1
Line 4
Line 2
Line 3 (*)
Correct Correct
37. Which of the following statements can be compiled?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
List list = new ArrayList<String>(); (*)
List<String> list = new ArrayList<String>(); (*)
List<?> list = new ArrayList<String>(); (*)
List<Object> list = new ArrayList<String>();
Incorrect Incorrect. Refer to Section 2 Lesson 4.
38. What is the output from the following code snippet?
Integer[] ar = {1, 2, 1, 3};
Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));
set.add(4);
for (Integer element : set) {
System.out.print(element);
} Mark for Review
(1) Points
11234
12134
1234 (*)
1213
Correct Correct
39. A collection is an interface in the Java API.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
40. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
41. Which class is an ordered collection that may contain duplicates? Mark for Review
(1) Points
array
set
enum
list (*)
Correct Correct
42. What is a set? Mark for Review
(1) Points
A collection of elements that does not contain duplicates. (*)
A keyword in Java that initializes an ArrayList.
A collection of elements that contains duplicates.
Something that enables you to create a generic class without specifying a type between angle brackets <>.
Correct Correct
43. Which line contains a compilation error?
interface Shape {}
class Circle implements Shape{}
public class Test{
public static void main(String[] args) {
List<? extends Shape> ls = new ArrayList<Circle>(); // Line 1
List<Circle> lc = new ArrayList<Circle>(); // Line 2
Circle c = new Circle();
ls.add(c); // Line 3
lc.add(c); // Line 4
}
} Mark for Review
(1) Points
Line 4
Line 1
Line 2
Line 3 (*)
Correct Correct
44. You can only implement one interface in a class.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
45. Classes define and implement what? Mark for Review
(1) Points
Some methods with implementations
All methods with implementations
Variables and methods (*)
All method definitions without any implementations
Constants and all methods with implementations
Correct Correct
46. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points
True (*)
False
Correct Correct
47. Which one of the following would allow you to define an interface for Animal? Mark for Review
(1) Points
public Animal extends Interface {}
public interface Animal {} (*)
public class Animal implements Interface {}
public class Animal {}
Correct Correct
48. The state of an object differentiates it from other objects of the same class.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
49. Which one of the following statements is true? Mark for Review
(1) Points
A class is a template that defines the features of an object (*)
A class is a Java primitive
A Java program can only contain one super class
A class is an intance of an object
Correct Correct
50. Immutable classes do allow instance variables to be changed by overriding methods.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
OJP 3
Section 1
(Answer all questions in this section)
1. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
2. Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
3. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. Which of the following statements about arrays and ArrayLists in Java are true?
I. An Array has a fixed length.
II. An Array can grow and shrink dynamically as required.
III. An ArrayList can store multiple object types.
IV. In an ArrayList you need to know the length and the current number of elements stored.
Mark for Review
(1) Points
I and III only (*)
II and IV only
I, II, and III only
I, II, III and IV
None of these
Correct Correct
5. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
Section 1
(Answer all questions in this section)
6. In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. What is the final value of result from the following code snippet?
int i = 1;
int [] id = new int [3];
int result = id [i];
result = result + i; Mark for Review
(1) Points
The code will compile, result has the value of 1 (*)
The code will compile, result has the value of 2
An exception is thrown.
The code will compile, result has the value of 0
The code will not compile, result has the value of 2
Correct Correct
8. What is the output from the following code?
int x=5;
if (x>6)
System. out. println("x>l");
else if (x>=5)
System. out .println("x>=5");
else if (x<10)
System. out. println("x<10");
else
System.out.println("none of the above"); Mark for Review
(1) Points
x<10
None of these answers are correct
x>6
x>=5 (*)
Correct Correct
9. Examine the partial class declaration below:
class Foo{
public Foo(String s,int i ){
this(i);
}
public Foo(int i){
}
public Foo(int i,int j){
}
}
Which of following statements can not be used to create a instance of Foo?
Mark for Review
(1) Points
Foo f=new Foo("java",1);
Foo f=new Foo(1,2);
Foo f=new Foo(); (*)
Foo f=new Foo(1);
Incorrect incorrect. Refer to Section 1 Lesson 1.
Section 2
(Answer all questions in this section)
10. Virtual method invocation requires that the superclass method is defined as which of the following? Mark for Review
(1) Points
A private final method.
A public static method.
A public final method.
A default final method.
A public method. (*)
Incorrect Incorrect. Refer to Section 2 Lesson 2.
Section 2
(Answer all questions in this section)
11. A downward cast of a superclass to subclass allows you to access a subclass specialized method call.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. You can always upcast a subclass to an interface provided you don't need to access any members of the concrete class.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 2.
13. Which line contains an compilation error?
interface Shape {}
interface InnerShape extends Shape{}
class Circle implements Shape{ }
class InnerCircle extends Circle{}
class Rectangle implements Shape{}
public class Tester {
public static void main(String[] args) {
Circle c= new Circle();
InnerCircle ic = new InnerCircle();
Rectangle rect = new Rectangle();
System.out.print(c instanceof InnerCircle); //Line 1
System.out.print(ic instanceof Circle); //Line 2
System.out.print(rect instanceof InnerCircle); //Line 3
System.out.print(rect instanceof Shape); //Line 4
}
} Mark for Review
(1) Points
Line 1
Line 3 (*)
Line 2
Line 4
Correct Correct
14. When line 10 is executed, which method will be called?
1 class Account {
2 public void deposit(int amt, int amt1) { }
3 public void deposit(int amt){ }
4 }
5 public class CreditAccount extends Account {
6 public void deposit() { }
7 public void deposit(int amt) {}
8 public static void main(String args[]){
9 Account account = new CreditAccount();
10 account.deposit(10);
11 }
12 } Mark for Review
(1) Points
line 3
line 7 (*)
line 6
line 2
Correct Correct
15. An abstract class can implement its methods.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 2.
Section 2
(Answer all questions in this section)
16. Upward casting an object instance means you can't access subclass specific methods.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
17. All classes can by subclassed. Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
18. Classes define and implement what? Mark for Review
(1) Points
Some methods with implementations
All methods with implementations
All method definitions without any implementations
Variables and methods (*)
Constants and all methods with implementations
Correct Correct
19. An interface can implement methods.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
20. Which two statements are equivalent to line 2?
(Choose Two) 1. public interface Account{
2. int accountID=100;
3. } Mark for Review
(1) Points
(Choose all correct answers)
private int accountID=100;
protected int accountID=100;
static int accountID=100; (*)
Abstract int accountID=100;
Final int accountID=100; (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
Section 2
(Answer all questions in this section)
21. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points
True (*)
False
Correct Correct
22. Which one of the following would allow you to define an interface for Animal? Mark for Review
(1) Points
public interface Animal {} (*)
public Animal extends Interface {}
public class Animal implements Interface {}
public class Animal {}
Incorrect Incorrect. Refer to Section 2 Lesson 1.
23. Immutable classes can be subclassed.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
24. A generic class is a type of class that associates one or more non-specific Java types with it.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
25. < ? extends Animal > would only allow classes or subclasses of Animal to be used.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 2
(Answer all questions in this section)
26. Generic methods are required to be declared as static.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 3.
27. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 3.
28. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 4.
29. What is the output from the following code snippet?
Integer[] ar = {1, 2, 1, 3};
Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));
set.add(4);
for (Integer element : set) {
System.out.print(element);
} Mark for Review
(1) Points
12134
11234
1234 (*)
1213
Correct Correct
30. What is a set? Mark for Review
(1) Points
Something that enables you to create a generic class without specifying a type between angle brackets <>.
A collection of elements that contains duplicates.
A keyword in Java that initializes an ArrayList.
A collection of elements that does not contain duplicates. (*)
Section 2
(Answer all questions in this section)
31. Which code inserted into the code below guarantees that the program will output [1,2]?
import java.util.*;
public class Example{
public static void main(String[] args){
//insert code here
set.add(2);
set.add(1);
System.out.println(set);
}
} Mark for Review
(1) Points
Set set = new LinkedHashSet();
Set set = new HashSet();
List set = new SortedList();
Set set = new SortedSet();
Set set = new TreeSet(); (*)
Correct Correct
32. A collection is an interface in the Java API.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
33. What is the output from the following code snippet?
TreeSet<String>t=new TreeSet<String>();
if (t.add("one"))
if (t.add("two"))
if (t.add ("three"))
t.add("four");
for (String s : t)
System.out.print (s); Mark for Review
(1) Points
onetwothreefour
fouronethreetwo (*)
twofouronethree
The code does not compiles.
Correct Correct
34. Which of these could be a set? Why? Mark for Review
(1) Points
{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)
All of the above are sets because they are collections that can be made to fit any of the choices.
Incorrect Incorrect. Refer to Section 2 Lesson 4.
35. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
n
log(n) (*)
n*log(n)
n^2
Section 2
(Answer all questions in this section)
36. Selection sort is efficient for large arrays.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 6.
37. 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 Correct
38. 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 Correct
39. A sequential 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 Correct
40. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
41. A sequential 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 Correct
42. Binary searches can be performed on sorted and unsorted data.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
43. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {
2,//insert code here
3. s.put ("StudentID", 123);
4.} Mark for Review
(1) Points
(Choose all correct answers)
HashMap s= new HashMap(); (*)
SortedMap s= new TreeMap(); (*)
Map s= new SortedMap();
ArrayList s= new ArrayList();
Incorrect Incorrect. Refer to Section 2 Lesson 5.
44. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Because you can remove elements from the beginning of it. (*)
Because you can remove elements from the end of it. (*)
Because you can not add element to the beginning of it.
Because you can add elements to the end of it. (*)
Correct Correct
45. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points
True (*)
False
Section 2
(Answer all questions in this section)
46. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
47. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
48. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Incorrect Incorrect. Refer to Section 2 Lesson 5.
49. Which of the following describes a deque. Mark for Review
(1) Points
It is pronounced "deck" for short.
It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.
All of the above. (*)
Correct Correct
50. To allow our classes to have a natural order we could implement the Comparable interface.
True or false? Mark for Review
(1) Points
True (*)
False
(Answer all questions in this section)
1. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
2. Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
3. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. Which of the following statements about arrays and ArrayLists in Java are true?
I. An Array has a fixed length.
II. An Array can grow and shrink dynamically as required.
III. An ArrayList can store multiple object types.
IV. In an ArrayList you need to know the length and the current number of elements stored.
Mark for Review
(1) Points
I and III only (*)
II and IV only
I, II, and III only
I, II, III and IV
None of these
Correct Correct
5. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
Section 1
(Answer all questions in this section)
6. In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. What is the final value of result from the following code snippet?
int i = 1;
int [] id = new int [3];
int result = id [i];
result = result + i; Mark for Review
(1) Points
The code will compile, result has the value of 1 (*)
The code will compile, result has the value of 2
An exception is thrown.
The code will compile, result has the value of 0
The code will not compile, result has the value of 2
Correct Correct
8. What is the output from the following code?
int x=5;
if (x>6)
System. out. println("x>l");
else if (x>=5)
System. out .println("x>=5");
else if (x<10)
System. out. println("x<10");
else
System.out.println("none of the above"); Mark for Review
(1) Points
x<10
None of these answers are correct
x>6
x>=5 (*)
Correct Correct
9. Examine the partial class declaration below:
class Foo{
public Foo(String s,int i ){
this(i);
}
public Foo(int i){
}
public Foo(int i,int j){
}
}
Which of following statements can not be used to create a instance of Foo?
Mark for Review
(1) Points
Foo f=new Foo("java",1);
Foo f=new Foo(1,2);
Foo f=new Foo(); (*)
Foo f=new Foo(1);
Incorrect incorrect. Refer to Section 1 Lesson 1.
Section 2
(Answer all questions in this section)
10. Virtual method invocation requires that the superclass method is defined as which of the following? Mark for Review
(1) Points
A private final method.
A public static method.
A public final method.
A default final method.
A public method. (*)
Incorrect Incorrect. Refer to Section 2 Lesson 2.
Section 2
(Answer all questions in this section)
11. A downward cast of a superclass to subclass allows you to access a subclass specialized method call.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. You can always upcast a subclass to an interface provided you don't need to access any members of the concrete class.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 2.
13. Which line contains an compilation error?
interface Shape {}
interface InnerShape extends Shape{}
class Circle implements Shape{ }
class InnerCircle extends Circle{}
class Rectangle implements Shape{}
public class Tester {
public static void main(String[] args) {
Circle c= new Circle();
InnerCircle ic = new InnerCircle();
Rectangle rect = new Rectangle();
System.out.print(c instanceof InnerCircle); //Line 1
System.out.print(ic instanceof Circle); //Line 2
System.out.print(rect instanceof InnerCircle); //Line 3
System.out.print(rect instanceof Shape); //Line 4
}
} Mark for Review
(1) Points
Line 1
Line 3 (*)
Line 2
Line 4
Correct Correct
14. When line 10 is executed, which method will be called?
1 class Account {
2 public void deposit(int amt, int amt1) { }
3 public void deposit(int amt){ }
4 }
5 public class CreditAccount extends Account {
6 public void deposit() { }
7 public void deposit(int amt) {}
8 public static void main(String args[]){
9 Account account = new CreditAccount();
10 account.deposit(10);
11 }
12 } Mark for Review
(1) Points
line 3
line 7 (*)
line 6
line 2
Correct Correct
15. An abstract class can implement its methods.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 2 Lesson 2.
Section 2
(Answer all questions in this section)
16. Upward casting an object instance means you can't access subclass specific methods.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
17. All classes can by subclassed. Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
18. Classes define and implement what? Mark for Review
(1) Points
Some methods with implementations
All methods with implementations
All method definitions without any implementations
Variables and methods (*)
Constants and all methods with implementations
Correct Correct
19. An interface can implement methods.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
20. Which two statements are equivalent to line 2?
(Choose Two) 1. public interface Account{
2. int accountID=100;
3. } Mark for Review
(1) Points
(Choose all correct answers)
private int accountID=100;
protected int accountID=100;
static int accountID=100; (*)
Abstract int accountID=100;
Final int accountID=100; (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
Section 2
(Answer all questions in this section)
21. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points
True (*)
False
Correct Correct
22. Which one of the following would allow you to define an interface for Animal? Mark for Review
(1) Points
public interface Animal {} (*)
public Animal extends Interface {}
public class Animal implements Interface {}
public class Animal {}
Incorrect Incorrect. Refer to Section 2 Lesson 1.
23. Immutable classes can be subclassed.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 1.
24. A generic class is a type of class that associates one or more non-specific Java types with it.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
25. < ? extends Animal > would only allow classes or subclasses of Animal to be used.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 2
(Answer all questions in this section)
26. Generic methods are required to be declared as static.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 3.
27. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 3.
28. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 4.
29. What is the output from the following code snippet?
Integer[] ar = {1, 2, 1, 3};
Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));
set.add(4);
for (Integer element : set) {
System.out.print(element);
} Mark for Review
(1) Points
12134
11234
1234 (*)
1213
Correct Correct
30. What is a set? Mark for Review
(1) Points
Something that enables you to create a generic class without specifying a type between angle brackets <>.
A collection of elements that contains duplicates.
A keyword in Java that initializes an ArrayList.
A collection of elements that does not contain duplicates. (*)
Section 2
(Answer all questions in this section)
31. Which code inserted into the code below guarantees that the program will output [1,2]?
import java.util.*;
public class Example{
public static void main(String[] args){
//insert code here
set.add(2);
set.add(1);
System.out.println(set);
}
} Mark for Review
(1) Points
Set set = new LinkedHashSet();
Set set = new HashSet();
List set = new SortedList();
Set set = new SortedSet();
Set set = new TreeSet(); (*)
Correct Correct
32. A collection is an interface in the Java API.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
33. What is the output from the following code snippet?
TreeSet<String>t=new TreeSet<String>();
if (t.add("one"))
if (t.add("two"))
if (t.add ("three"))
t.add("four");
for (String s : t)
System.out.print (s); Mark for Review
(1) Points
onetwothreefour
fouronethreetwo (*)
twofouronethree
The code does not compiles.
Correct Correct
34. Which of these could be a set? Why? Mark for Review
(1) Points
{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)
All of the above are sets because they are collections that can be made to fit any of the choices.
Incorrect Incorrect. Refer to Section 2 Lesson 4.
35. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
n
log(n) (*)
n*log(n)
n^2
Section 2
(Answer all questions in this section)
36. Selection sort is efficient for large arrays.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 2 Lesson 6.
37. 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 Correct
38. 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 Correct
39. A sequential 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 Correct
40. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
41. A sequential 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 Correct
42. Binary searches can be performed on sorted and unsorted data.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
43. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {
2,//insert code here
3. s.put ("StudentID", 123);
4.} Mark for Review
(1) Points
(Choose all correct answers)
HashMap s= new HashMap(); (*)
SortedMap s= new TreeMap(); (*)
Map s= new SortedMap();
ArrayList s= new ArrayList();
Incorrect Incorrect. Refer to Section 2 Lesson 5.
44. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Because you can remove elements from the beginning of it. (*)
Because you can remove elements from the end of it. (*)
Because you can not add element to the beginning of it.
Because you can add elements to the end of it. (*)
Correct Correct
45. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points
True (*)
False
Section 2
(Answer all questions in this section)
46. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
47. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
48. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Incorrect Incorrect. Refer to Section 2 Lesson 5.
49. Which of the following describes a deque. Mark for Review
(1) Points
It is pronounced "deck" for short.
It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.
All of the above. (*)
Correct Correct
50. To allow our classes to have a natural order we could implement the Comparable interface.
True or false? Mark for Review
(1) Points
True (*)
False
Langganan:
Postingan (Atom)