Senin, 08 Mei 2017

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

Tidak ada komentar:

Posting Komentar