Minggu, 07 Mei 2017

OJP 1

1. Which of the following statements about unit testing is/are true

I. When all unit tests succeed, you can have high confidence your code is solid.
II. If a unit test fails, you don?t proceed until the code is fixed and the test succeeds.
III. Unit testing can help developer find problems early in the development cycle
 Mark for Review
(1) Points

I only

I and II only

II and III only (*)

I, II, and III

None of these




2. 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




3. 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. (*)





4. 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 (*)





5. Which of the following is not a good technique to follow when reading code written by others? Mark for Review
(1) Points

Find the author of the code and ask him how it works. (*)

Learn the high level structure and starting point, and then figure out how it branches.

Build and run the code.

Perform testing.

Understand the constructs.





6. Examine the following code snippet. What is this an example of?

public class Car extends Vehicle {
public Car() {
...
}
} Mark for Review
(1) Points

Encapsulation

Polymorphism

Comments

Inheritance (*)





7. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review
(1) Points

(Choose all correct answers)

protected (*)

abstract

public (*)

final






8. Which statements are true?(Choose Three) Mark for Review
(1) Points

(Choose all correct answers)


In a constructor, you can call a superclass constructor. (*)

You can declare more than one constructor in a class declaration. (*)

Since a constructor can not return any value, it should be declared as void.

A constructor can not be overloaded.

You can use access modifiers to control which other classes can call the constructor. (*)






9. You declare a method:
public void act(Student s){}

Which of following arguments can be passed into the method? (Choose Two) Mark for Review
(1) Points

(Choose all correct answers)


Type of Object class

Interface

Type of Student class (*)

Type of the subclass of Student (*)






10. What is the output from the following code snippet?

public static void main(String[] args){

 List li=new ArrayList();
        li.add(1);
        li.add(2);
        print(li);
}
    public static void print(List list) {
    for (Number n : list)
        System.out.print(n + " ");
    } Mark for Review
(1) Points


1

2

The code will not compile.

1 2 (*)





11. Examine the code below.  Which statement about this code is true?

1.class Shape {  }
2.class Circle extends Shape {  }
3.class Rectangle extends Shape { }
4.class Node {  }
5.public class Test{
6.public static void main(String[] args){
7.Node nc = new Node<>();
8.Node  ns = nc;
}
} Mark for Review
(1) Points


The code compiles.

An error at line 8 causes compilation to fail. (*)

An error at line 7 causes compilation to fail.

An error at line 4 causes compilation to fail.






12. The following code will compile.
True or False?

class Node implements Comparable{
    public int compareTo(T obj){return 1;}
}

class Test{
    public static void main(String[] args){
        Node nc=new Node<>();
        Comparable com=nc;
}
 Mark for Review
(1) Points


True (*)

False






13. Which of the following correctly initializes an object named cell of the class Telephones whose generic type is Cellular? Mark for Review
(1) Points


Telephones cell = new Telephones(Cellular c);

Telephones(Cellular) cell = new Telephones(Cellular);

Telephones<> cell = new Telephones<>(Cellular c);

Telephones <Cellular> cell = new Telephones <Cellular>(); (*)

None of the these.






14. A HashMap can only store String types.
True or false? Mark for Review
(1) Points


True

False (*)






15. 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





16. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points


True (*)

False






17. A HashMap can store duplicates.
True or false? Mark for Review
(1) Points


True

False (*)






18. Stacks are identical to Queues.
True or false? Mark for Review
(1) Points


True

False (*)






19. Which of the following correctly defines a queue? Mark for Review
(1) Points


Something that enables you to create a generic class without specifying a type between angle brackets <>.

It is a keyword in Java that restrict the use of the code to local users only.

A list of elements with a first in last out order.

A list of elements with a first in first out order. (*)






20. Where you enqueue an element in the list? Mark for Review
(1) Points


removes it from the front of the list

adds it to the start of the list

adds it to the end of the list (*)

removes it from the end of the list






21. 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. (*)






22. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?
The steps are shown below:

{'M', 'S', 'A', 'T', 'H'}
{'M', 'A', 'S', 'T', 'H'}
{'A', 'M', 'S', 'T', 'H'}
{'A', 'M', 'S', 'H', 'T'}
{'A', 'M', 'H', 'S', 'T'}
{'A', 'H', 'M', 'S', 'T'} Mark for Review
(1) Points


Sequential Search

Bubble Sort (*)

Selection Sort

Binary Search

Merge Sort







23. 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






24. Why might a sequential search be inefficient? Mark for Review
(1) Points


It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.






25. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed? Mark for Review
(1) Points


Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above





26. Why might a sequential search be inefficient? Mark for Review
(1) Points


It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.






27. 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






28. 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 (*)






29. 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, 17, 22, 28, 29, 3, 50, 71, 83} (*)

{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}






30. Which of the following statements can be compiled?(Choose Three) Mark for Review
(1) Points

(Choose all correct answers)


List<Object> list = new ArrayList<String>();

List<?> list = new ArrayList<String>(); (*)

List list = new ArrayList<String>(); (*)

List<String> list = new ArrayList<String>(); (*)






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 SortedSet();

Set set = new HashSet();

Set set = new TreeSet(); (*)

List set = new SortedList();

Set set = new LinkedHashSet();






32. Sets may contain duplicates.
True or false? Mark for Review
(1) Points


True

False (*)






33. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points


True

False (*)






34. 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






35. Which interface forms the root of the collections hierarchy? Mark for Review
(1) Points


java.util.Collections

java.util.Map

java.util.List

java.util.Collection (*)




6. 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 (*)






7. 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






8.Which of the following are important to your survival as a programmer? Mark for Review
(1) Points


Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)






9. 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







10. The instanceof operator allows you to determine the type of an object.
True or false? Mark for Review
(1) Points


True (*)

False







36. The following code is valid when working with the Collection Interface.
Collection collection = new Collection()d;
True or false? Mark for Review
(1) Points


True

False (*)





37. Which one of the following statements is true? Mark for Review
(1) Points


A Java program can only contain one super class

A class is a template that defines the features of an object (*)

A class is a Java primitive

A class is an intance of an object






38. An interfaces can declare public constants.
True or False? Mark for Review
(1) Points


True (*)

False






39. Immutable classes do allow instance variables to be changed by overriding methods.
True or false? Mark for Review
(1) Points


True

False (*)






40. In general, classes can be made immutable by placing a final key word before the class keyword.
True or false? Mark for Review
(1) Points


False

True (*)





41. Immutable classes can be subclassed.
True or false? Mark for Review
(1) Points


True

False (*)






42. The state of an object differentiates it from other objects of the same class.
True or False? Mark for Review
(1) Points


True (*)

False






43. A method with default access can be subclassed.
True or false? Mark for Review
(1) Points


True

False (*)






44. 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






45. Virtual method invocation occurs: Mark for Review
(1) Points


When the method of a subclass is used on a superclass reference. (*)

When the method of a superclass is used on a superclass reference.

When the method of a subclass is used on a subclass reference.

Not part of polymorphism.






46. The instanceof operator works with class instances and primitive data types.
True or false? Mark for Review
(1) Points


True

False (*)






47. Upward casting an object instance means you can't access subclass specific methods.
True or false? Mark for Review
(1) Points


True (*)

False






48. 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 must be difined by using the abstract keyword. (*)

An abstract class must contain abstrct method.

An abstract class can define constructor. (*)






49. Java provides virtual method invocation as a feature and it doesn't require specialized coding.
True or false? Mark for Review
(1) Points


True (*)

False






50. The instanceof operator is a boolean comparison operator.
True or false? Mark for Review
(1) Points


True (*)

False







6. 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 (*)






7. 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






8. Which of the following are important to your survival as a programmer? Mark for Review
(1) Points


Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)






9. 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






10. The instanceof operator allows you to determine the type of an object.
True or false? Mark for Review
(1) Points


True (*)

False





11. The instanceof operator is a boolean comparison operator.
True or false? Mark for Review
(1) Points


True (*)

False





12. Java provides virtual method invocation as a feature and it doesn't require specialized coding.
True or false? Mark for Review
(1) Points


True (*)

False






13. The instanceof operator works with class instances and primitive data types.
True or false? Mark for Review
(1) Points


True

False (*)






14. 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


An error at line 6 causes compilation to fail. (*)

Compilation is successful.

An error at line 2 causes compilation to fail.

An error at line 4 causes compilation to fail.





15. Virtual method invocation occurs when you try to call a superclass method.
True or false? Mark for Review
(1) Points


True

False (*)






16. Virtual method invocation occurs: Mark for Review
(1) Points


When the method of a superclass is used on a superclass reference.

When the method of a subclass is used on a subclass reference.

Not part of polymorphism.

When the method of a subclass is used on a superclass reference. (*)







17. 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. (*)







18. 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 end of it. (*)

Because you can remove elements from the beginning of it. (*)

Because you can not add element to the beginning of it.

Because you can add elements to the end of it. (*)






19. A LinkedList is a type of Stack.
True or false? Mark for Review
(1) Points


True (*)

False






20. Stacks are identical to Queues.
True or false? Mark for Review
(1) Points


True

False (*)





21. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points


Arrays

Stacks (*)

HashMaps

Enums






22. Which of the following correctly defines a queue? Mark for Review
(1) Points


A list of elements with a first in first out order. (*)

Something that enables you to create a generic class without specifying a type between angle brackets <>.

A list of elements with a first in last out order.

It is a keyword in Java that restrict the use of the code to local users only.





23. Which scenario best describes a queue? 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 queue.






24. What are maps that link a Key to a Value? Mark for Review
(1) Points


HashMaps (*)

ArrayLists

Arrays

HashSets






25. The local petting zoo is writing a program to be able to collect group animals according to species to better keep track of what animals they have.
Which of the following correctly defines a collection that may create these types of groupings for each species at the zoo? Mark for Review
(1) Points


public class
animalCollection {...}(*) (*)

public class
animalCollection(AnimalType T) {...}

public class
animalCollection {...}

public class
animalCollection(animalType) {...}

None of the these.






26. Enumerations (enums) are useful for storing data : Mark for Review
(1) Points


You cannot store data in an enum.

When the class is a subclass of Object.

When you know all of the possibilities of the class (*)

When the class is constantly changing






27. Generic methods are required to be declared as static.
True or False? Mark for Review
(1) Points


True

False (*)






28. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points


True

False (*)





29. 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






30. Which of the following best describes lexicographical order? Mark for Review
(1) Points


A simple sorting algorithm that is inefficient on large arrays.

An order based on the ASCII value of characters. (*)

A complex sorting algorithm that is efficient on large arrays.

The order of indicies after an array has been sorted.






31. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed? Mark for Review
(1) Points


Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above






32. Why might a sequential search be inefficient? Mark for Review
(1) Points


It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.






33. 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 (*)






34. Why might a sequential search be inefficient? Mark for Review
(1) Points


It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.






35.Of the options below, what is the fastest run-time? Mark for Review
(1) Points


n

n*log(n)

log(n) (*)

n^2





36. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?
The steps are shown below:

{'M', 'S', 'A', 'T', 'H'}
{'M', 'A', 'S', 'T', 'H'}
{'A', 'M', 'S', 'T', 'H'}
{'A', 'M', 'S', 'H', 'T'}
{'A', 'M', 'H', 'S', 'T'}
{'A', 'H', 'M', 'S', 'T'} Mark for Review
(1) Points


Binary Search

Selection Sort

Merge Sort

Sequential Search

Bubble Sort (*)






37. In general, classes can be made immutable by placing a final key word before the class keyword.
True or false? Mark for Review
(1) Points


False

True (*)






38. You can only implement one interface in a class.
True or False? Mark for Review
(1) Points


True

False (*)






39. Classes define and implement what? Mark for Review
(1) Points


All method definitions without any implementations

Constants and all methods with implementations

All methods with implementations

Some methods with implementations

Variables and methods (*)






40. Immutable classes can be subclassed.
True or false? Mark for Review
(1) Points


True

False (*)





41. Modeling classes for a business problem requires understanding of the business not Java. True or false? Mark for Review
(1) Points


True

False (*)






42. A method with default access can be subclassed.
True or false? Mark for Review
(1) Points


True

False (*)





43. 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)


static int accountID=100; (*)

private int accountID=100;

protected int accountID=100;

Abstract int accountID=100;

Final int accountID=100; (*)





44. What is a set? Mark for Review
(1) Points


A collection of elements that contains duplicates.

A collection of elements that does not contain duplicates. (*)

Something that enables you to create a generic class without specifying a type between angle brackets <>.

A keyword in Java that initializes an ArrayList.






45. Which of the following statements can be compiled?(Choose Three) Mark for Review
(1) Points

(Choose all correct answers)


List<Object> list = new ArrayList<String>();

List<String> list = new ArrayList<String>(); (*)

List list = new ArrayList<String>(); (*)

List<?> list = new ArrayList<String>(); (*)






6. Choose the best definiton for a collection. Mark for Review
(1) Points


It is an interface in the java.util package that is used to define a group of objects. (*)

It enables you to create a generic class without specifying a type between angle brackets <>.

It is a special type of class that is associated with one or more non-specified Java type.

It is a subclass of List.






47. Sets may contain duplicates.
True or false? Mark for Review
(1) Points


True

False (*)






48. Which is the correct way to initialize a HashSet? Mark for Review
(1) Points


ClassMates = public class
HashSet();

classMates = new HashSet[String]();

HashSet classMates =
new HashSet(); (*)

String classMates = new
String();






49. Which interface forms the root of the collections hierarchy? Mark for Review
(1) Points


java.util.Map

java.util.Collection (*)

java.util.Collections

java.util.List






50. What is the result from the following code snippet?

interface Shape {}
class Circle implements Shape{}
class Rectangle implements Shape{}
public class Test{
 public static void main(String[] args) {
  List ls= new ArrayList<Shape>();//line 1
  ls.add(new Circle());
  ls.add(new Rectangle());// line 2
  ls.add(new Integer(1));// line 3
  System.out.println(ls.size());// line 4
 } Mark for Review
(1) Points


3 (*)

Compilation error at line 1

Compilation error at line 4

Compilation error at line 2

Compilation error at line 3






1. Which statement is true when run the following statement?

1. String str = null;
2. if ((str != null) && (str.length() > 1)) {
3. System.out.println("great that number 1");
4. } else if ((str != null) & (str.length() < 2)) {
5. System.out.println("less than number 2");
6. } Mark for Review
(1) Points


The code compiles and will throw an exception at line 4. (*)

The code compiles and will throw an exception at line 5

The code does not compile.

The code compiles and will throw an exception at line 3.

The code compiles and will throw an exception at line 2.






2. A class can be extended by more than one class. True or False? Mark for Review
(1) Points


True (*)

False






3. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review
(1) Points

(Choose all correct answers)


public (*)

protected (*)

abstract

final






4. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points


True (*)

False






5. Which statement is true for the class java.util.ArrayList? Mark for Review
(1) Points


The elements in the collection are ordered. (*)

The elements in the collection are accessed using key.

The elements in the collection are synchronized.

The elements in the collection are immutable.






6. 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





7. 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






8. When an object is able to pass on its state and behaviors to its children, this is called: Mark for Review
(1) Points


Encapsulation

Isolation

Polymorphism

Inheritance (*)






9. Which of the following are important to your survival as a programmer? Mark for Review
(1) Points


Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)








10. Which of the following best describes lexicographical order? Mark for Review
(1) Points


A complex sorting algorithm that is efficient on large arrays.

An order based on the ASCII value of characters. (*)

The order of indicies after an array has been sorted.

A simple sorting algorithm that is inefficient on large arrays.






11. Of the options below, what is the fastest run-time? Mark for Review
(1) Points


n^2

log(n) (*)

n

n*log(n)







12. 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






13. 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






14. 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 (*)






15. 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}

{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)






16. Why might a sequential search be inefficient? Mark for Review
(1) Points


It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.






17. 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






18. In general, classes can be made immutable by placing a final key word before the class keyword.
True or false? Mark for Review
(1) Points


True (*)

False






19. Immutable classes can be subclassed.
True or false? Mark for Review
(1) Points


True

False (*)







20. 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






21. Interfaces define what? Mark for Review
(1) Points


Constants and all methods with implementations

Variables and methods

Some methods with implementations

All method definitions without any implementations (*)

All methods with implementations






22. Making a class immutable means: Mark for Review
(1) Points


That it cannot be extended. (*)

To create an instance of the class.

To create a sub class from a parent class

That it is directly subclassed from the Object class







23. Modeling classes for a business problem requires understanding of the business not Java. True or false? Mark for Review
(1) Points


True

False (*)







24. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points


True (*)

False






25. Which method will force a subclass to implement it? Mark for Review
(1) Points


Public native double act();

Abstract public void act(); (*)

Protected void act(String name){}

Static void act(String name) {}

Public double act();





26. Virtual method invocation occurs when you try to call a superclass method.
True or false? Mark for Review
(1) Points


True

False (*)






27. Virtual method invocation must be defined with the instanceof operator.
True or false? Mark for Review
(1) Points


True

False (*)






28. A upward cast means all instance variables of the subclass are permanently lost to the instance.
True or false? Mark for Review
(1) Points


True

False (*)






29. Calling a subclass method by referring to a superclass works because you have access to all specialized methods through virtual method invocation.
True or false? Mark for Review
(1) Points


True

False (*)






30. 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 4

Line 2






31. Which two of the following statements are true? (Choose Two) Mark for Review
(1) Points

(Choose all correct answers)


An abstract class must be difined by using the abstract keyword. (*)

An abstract class can define constructor. (*)

An abstract class must contain abstrct method.

An abstract class can create subclass and be constructed.







32. Which interface forms the root of the collections hierarchy? Mark for Review
(1) Points


java.util.Collection (*)

java.util.Map

java.util.List

java.util.Collections







33. Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review
(1) Points


vegetables[0] = "Cabbage";

vegetables += "Cabbage";

vegetables.add("Cabbage"); (*)

vegetables.get("Cabbage");







34. What is the result from the following code snippet?

interface Shape {}
class Circle implements Shape{}
class Rectangle implements Shape{}
public class Test{
 public static void main(String[] args) {
  List ls= new ArrayList<Shape>();//line 1
  ls.add(new Circle());
  ls.add(new Rectangle());// line 2
  ls.add(new Integer(1));// line 3
  System.out.println(ls.size());// line 4
 } Mark for Review
(1) Points


Compilation error at line 4

Compilation error at line 1

Compilation error at line 2

3 (*)

Compilation error at line 3







35. 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


1234 (*)

1213

11234

12134






36. 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<Object> list = new ArrayList<String>();

List list = new ArrayList<String>(); (*)







37. 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





38. Which class is an ordered collection that may contain duplicates? Mark for Review
(1) Points


enum

array

set

list (*)







39. 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





40. Generic methods can only belong to generic classes.
True or False? Mark for Review
(1) Points


True

False (*)





41. What is the output from the following code snippet?

public static void main(String[] args){

 List li=new ArrayList();
        li.add(1);
        li.add(2);
        print(li);
}
    public static void print(List list) {
    for (Number n : list)
        System.out.print(n + " ");
    } Mark for Review
(1) Points


The code will not compile.


2

1 2 (*)

1






42. An example of an upper bounded wildcard is. Mark for Review
(1) Points


ArrayList<? super Animal>

ArrayList<T>

ArrayList<?>

ArrayList<? extends Animal> (*)






43. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points


True (*)

False






44. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points


True (*)

False






45. 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. (*)






46. The Comparable interface includes a method called compareTo.
True or false? Mark for Review
(1) Points


True (*)

False






47. Which of the following methods adds a Key-Value map to a HashMap? Mark for Review
(1) Points


remove(Key, Value)

get(Key, Value)

put(Key, Value) (*)

add(Key, Value)






48. Which scenario best describes a queue? 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 queue.






49. A LinkedList is a type of Stack.
True or false? Mark for Review
(1) Points


True (*)

False





50. 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. (*)




2 komentar:

  1. 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
    }
    }

    BalasHapus