Jumat, 14 Juli 2017

OJP SECTION QUIZ 2

1.  What is the correct explanation of when this code will return true?
return str.matches(".*[0-9]{6}.*");  Mark for Review
(1) Points
    
  
 Any time that str contains two dots.
  
 Any time that str contains a sequence of 6 digits. (*)
  
 Any time that str has between zero and nine characters followed by a 6.
  
 Any time str contains a 6.
  
 Always.
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  2.  Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group for the last name considering that the string contactsName is always in the format lastName_firstName?  Mark for Review
(1) Points
    
  
 Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)
  
 Pattern namePattern = Pattern.compile("first_last");
  
 Pattern namePattern = new Pattern(last{5},first{5});
  
 Pattern namePattern = new Pattern();
  
 None of the above.
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  3.  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 (*)
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  4.  What does the dot (.) represent in regular expressions?  Mark for Review
(1) Points
    
  
 An indication for one or more occurrences of the preceding character.
  
 A match for any character. (*)
  
 A range specified between brackets that allows variability of a character.
  
 Nothing, it is merely a dot.
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  5.  One benefit to using groups with regular expressions is that you can segment a matching string and recall the segments (or groups) later in your program.
True or false?  Mark for Review
(1) Points
    
  
 True (*)
  
 False
  What is the function of the asterisk (*) in regular expressions?  Mark for Review
(1) Points
    
  
 Indicates that the preceding character may occur 0 or more times in a proper match. (*)
  
 Indicates that the preceding character may occur 1 or more times in a proper match.
  
 The asterisk has no function in regular expressions.
  
 Indicates that the preceding character may occur 0 or 1 times in a proper match.
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  7.  Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and false otherwise. Which of the following code segments completes this task?(Choose Two)  Mark for Review
(1) Points
    
   (Choose all correct answers)
    
  
 return str.matches(".?"); (*)
  
 if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
  
 return str.contains(".");
  
 return str.matches("[a-z]*");
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
    
  8.  Which of the following are true about parsing a String?(Choose Three)  Mark for Review
(1) Points
    
   (Choose all correct answers)
    
  
 It is a way of dividing a string into a set of sub-strings. (*)
  
 It is possible to use the String.split() method to parse a string. (*)
  
 It is not possible to parse a string using regular expressions.
  
 It is possible to use a for loop to parse a string. (*)
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
    
  9.  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)
    
  
 Read the String backwards (from last element to first element). (*)
  
 Search for a specific character or String inside of the String. (*)
  
 Parse the String. (*)
  
 You don't use a FOR loop with Strings
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
    
  10.  Which of the following correctly initializes a StringBuilder?  Mark for Review
(1) Points
    
  
 StringBuilder sb = "This is my String Builder";
  
 StringBuilder sb = StringBuilder(500);
  
 StringBuilder sb = new StringBuilder(); (*)
  
 None of the above.
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
11.  Which of the following methods are StringBuilder methods?  Mark for Review
(1) Points
    
  
 append
  
 delete
  
 insert
  
 replace
  
 All of the above. (*)
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
    
  12.  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
    
  
 13 (*)
  
 10
  
 9
  
 12
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 3.
    
  13.  A non-linear recursive method is less expensive than a linear recursive method.
True or false?  Mark for Review
(1) Points
    
  
 True
  
 False (*)
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 3.
    
  14.  A linear recursion requires the method to call which direction?  Mark for Review
(1) Points
    
  
 Forward
  
 Backward (*)
  
 Both forward and backward
  
 None of the above
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 3.
    
  15.  The base case condition can work with a constant or variable.
True or false?  Mark for Review
(1) Points
    
  
 True (*)
  
 False
    
   
Incorrect  Incorrect. Refer to Section 3 Lesson 3.

OJP QUIZ SECTION

1.  Which of the following correctly defines a StringBuilder?  Mark for Review
(1) Points
   
 
 A class that represents a string-like object. (*)
 
 A method that adds characters to a string.
 
 There is no such thing as a StringBuilder in Java.
 
 A class inside the java.util.regex package.
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
   
  2.  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. (*)
 
 Parse the String. (*)
 
 Read the String backwards (from last element to first element). (*)
 
 You don't use a FOR loop with Strings
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
   
  3.  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
   
 
 91204
 
 Compile fails.
 
 91227
 
 9120423 (*)
 
 23
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
   
  4.  Which of the following correctly initializes a StringBuilder?  Mark for Review
(1) Points
   
 
 StringBuilder sb = "This is my String Builder";
 
 StringBuilder sb = StringBuilder(500);
 
 StringBuilder sb = new StringBuilder(); (*)
 
 None of the above.
   
  
Correct  Correct
   
  5.  Which of the following correctly defines Matcher?  Mark for Review
(1) Points
   
 
 A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
 
 A regular expression symbol that represents any character.
 
 A class in the java.util.regex package that stores the format of a regular expression.
 
 A method of dividing a string into a set of sub-strings.
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
6.  The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".
Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");
True or false?  Mark for Review
(1) Points
   
 
 True (*)
 
 False
   
  
Correct  Correct
   
  7.  Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and false otherwise. Which of the following code segments completes this task?(Choose Two)  Mark for Review
(1) Points
   
   (Choose all correct answers)
   
 
 return str.contains(".");
 
 return str.matches(".?"); (*)
 
 if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
 
 return str.matches("[a-z]*");
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
   
  8.  Which of the following correctly defines Pattern?  Mark for Review
(1) Points
   
 
 A method of dividing a string into a set of sub-strings.
 
 A regular expression symbol that represents any character.
 
 A class in the java.util.regex package that stores matches.
 
 A class in the java.util.regex package that stores the format of a regular expression. (*)
   
  
Correct  Correct
   
  9.  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 (*)
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
   
  10.  What is the correct explanation of when this code will return true?
return str.matches(".*[0-9]{6}.*");  Mark for Review
(1) Points
   
 
 Any time that str contains two dots.
 
 Any time that str contains a sequence of 6 digits. (*)
 
 Any time that str has between zero and nine characters followed by a 6.
 
 Any time str contains a 6.
 
 Always.
11.  What does the dot (.) represent in regular expressions?  Mark for Review
(1) Points
   
 
 An indication for one or more occurrences of the preceding character.
 
 A match for any character. (*)
 
 A range specified between brackets that allows variability of a character.
 
 Nothing, it is merely a dot.
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
   
  12.  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.
   
  13.  A base case can handle nested conditions.
True or false?  Mark for Review
(1) Points
   
 
 True (*)
 
 False
   
  
Correct  Correct
   
  14.  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.
   
  15.  Which two statements can create an instance of an array? (Choose Two)  Mark for Review
(1) Points
   
   (Choose all correct answers)
   
 
 Object oa = new double[5]; (*)
 
 char[] ca = "java";
 
 int[] ia = new int [5]; (*)
 
 int ia[][] = (1,2,3) (4,5,6);
 
 double da = new double [5];
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 3.

Senin, 08 Mei 2017

QUIZ 3 OJP

  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

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