You are on page 1of 15

27.

04
If the objects of a class are arranged into their natural order, then if object L is left of object R
what is true? Select one:

a. L.compareTo(R) is positive
b. R.compareTo(L) is negative Incorrect
c. L.compareTo(R) is zero
d. L.compareTo(R) is negative

What is ZURICH.compareTo(cairo)

a. a. zero
b. b. a positive integer
c. d. a negative integer

What is the value of (new Integer(5)).compareTo( new Integer(8) )?


a. a positive integer
b. a negative integer
c. 0
d. unpredictable

Which of these is an incorrect form of using method max() to obtain


maximum element?
a. max(Comparator comp)
b. max(Collection c)
c. max(Collection c, Comparator comp)
d. max(List c)

If X.compareTo(Y) is positive, then which of the following is true?


a. a. Y.compareTo(X) is unknown
b. b. Y.compareTo(X) is zero
c. c. Y.compareTo(X) is positive
d. d. Y.compareTo(X) is negative
Say that you are writing a class Book and wish it to implement the
Comparable interface. What method must Book contain?

a. Book compareTo( Object other )


b. int compareTo( Object other )
c. boolean compareTo( T other )
d. int compareTo( Book other )

What is the value of zebra.compareTo(emu)?


Select one:
a. a negative integer
b. unpredictable
c. 0
d. a positive integer

Which interface would we use to sort a class that can't be


modified?
a. java.lang.Comparable
b. java.util.Comparator

How many ways does the java.lang.Comparable interface allow us


to sort a collection?

a. 2

b. any number
c. 1
d. 0

If X.equals(Y) is true, then which of the following is true for most


classes that implement Comparable?
Select one:
a. X.compareTo(Y) is negative

b. Nothing can be said.


c. X.compareTo(Y) is positive
d. X.compareTo(Y) is zero

Which of these methods deletes all the elements from invoking


collection?
Select one:
a. clear()
b. delete()
c. reset()
d. refresh()

What is returned from both the compare() and


compareTo()methods?

a. char
b. string
c. int
d. boolean

What type of map would you use if you wanted a fast access
ordered map but didn't care about sorting?
a. TreeMap
b. Hashtable
c. HashMap
d. LinkedHashMap

You can't put null elements into Lists in the API?


:
a. TRUE
b. FALSE
What do Lists have in common?
a. an index
b. nothing
c. element uniqueness

Complexity of ArrayList get method is


a. O(2n)
b. O(n-1)
c. O(n)
d. O(1)

What type of set would you use if you wanted fast access and
didn't care about ordering?
a. HashSet
b. LinkedHashSet
c. TreeSet
The correct answer is: HashSet

Which of these interface handle sequences?


a. Set
b. List
c. Comparator
d. Collection

Can we have a sorted and unordered map?


a. Yes
b. No

What type of set would you use if you wanted a fast access
ordered set but didn't care about sorting?
a. LinkedHashSet
b. TreeSet
c. HashSet
Which method do we need to implement in the java.util.Comparator
interface?
a. sortTo()
b. compareTo()
c. compare()
d. sort()
The correct answer is: compare()

What type of exception is raised when we try run a program with


objects that are not mutually comparable in a sorted map?
a. OutOfBoundsException
b. RuntimeException
c. None
d. ClassCastException

Which does NOT implement the Collection interface?


a. Map
b. Set
c. None of these
d. List

Which of these interface declares core method that all collections


will have?
a. Comparator
b. set
c. Event Listner
d. Collection

What type of variables can we use with the java.util.Collections


Class?
a. primitive variables
b. neither
c. reference variables
d. both

What type of collection would we use if we wanted no duplicates?


a. Queue
b. List
c. Map
d. Set

Can we have a sorted and unordered set?


Select one:
a. Yes
b. No

You can't put null elements into Queues in the API?


Select one:
a. FALSE
b. TRUE

What type of set would you use if you wanted it sorted?


a. HashSet
b. LinkedHashSet
c. TreeSet

Which method do we need to implement in the


java.lang.Comparable interface?

a. compare()
b. sort()
c. compareTo()

d. sortTo()
How many ways does the java.lang.Comparable interface allow us to sort a
collection?

a. 2
b. any number
c. 1
d. 0

What is pit viper.compareTo(pit)

a. unknown
b. a negative integer
c. zero
d. a positive integer

What type of map would you use if you wanted it sorted?

a. Hashtable
b. HashMap
c. TreeMap
d. LinkedHashMap

Which of these methods deletes all the elements from invoking collection?

a. refresh()
b. reset()
c. clear()
d. delete()

Which of these is Basic interface that all other interface inherits?

a. List
b. Array
c. Set
d. Collection
What is Collection in Java?

a. A group of classes
b. A group of objects
c. None of the mentioned
d. A group of interfaces

What do maps care about:

a. Index
b. Speed
c. Uniqueness

What type of variables can we use with the java.util.Arrays class?

a. primitive variables
b. neither
c. reference variables
d. both

Which type of list implements the Queue interface”:


Select one:
a. LinkedList
b. ArrayList
c. Vector

What type of collections are Lists?

a. unordered
b. sorted
c. ordered
What is returned from both the compare() and compareTo() methods?

a. int
b. boolean
c. string
d. char
Which of these methods sets every element of a List to a specified object?:

a. Complete()
b. add()
c. fill()
d. set()
Which List would you use if wanted fast access and were doing lots of
insertions and deletions?

a. Vector
b. ArrayList
c. LinkedList
What type of collection does not extend the Collection interface?

a. Map
b. Set
c. Queue
d. List
What do sets care about:
Select one:
a. Uniqueness
b. Index
c. Speed
What should we use when get operations are more?

a. LinkedList
b. ArrayList
c. Any
Which of these interface is not a part of Java’s collection framework?

a. SortedMap
b. List
c. Set
d. SortedList
Which of these interface must contain a unique element?

a. Array
b. Set
c. List
d. Collection
What type of map would you use if you wanted fast access and didn't care
about ordering?
Select one:
a. Hashtable
b. LinkedHashMap
c. TreeMap
d. HashMap

Is the following code snippet valid? List aList = new ArrayList();


a. no
b. yes Incorrect

There are no direct implementation of the Collection interface?

a. TRUE
b. FALSE

If two arrays hold the same elements they are considered equal by the
Arrays.equals() method?

a. FALSE
b. TRUE
Which provides better performance for the insertion and removal from the
middle of the list?

a. LinkedList
b. Vector
c. ArrayList
d. All of these
What type of map would you use if you wanted a fast access ordered map but
didn't care about sorting?

a. LinkedHashMap
b. TreeMap
c. Hashtable
d. HashMap

We can use any object with the methods of the java.util.Arrays class?

a. No
b. Yes

What type of exception is raised when we run a program with objects that are
not mutually comparable in a sorted set?

a. None
b. OutOfBoundsException
c. ClassCastException
d. RuntimeException

A HashMap allows the existence of:

a. null values
b. None of these
c. one null key
d. All of these
16.02…………………………………………..

In the following method declaration, what is the name of the method?


public static void showMenu(String category) { }

a. void
b. public
c. static
d. showMenu
When the type of a method is defined as void, this indicates

a. the method returns nothing


b. the method returns zero
In the following method how many values are returned?
public static void syncPhone(int idNumber) {// }

a. 0
b. 2
c. 3
d. 1
Which of the following is NOT true about a method in Java?

a. Java methods can return no values


b. Java methods can have no parameters
c. Java methods can have more than one parameter
d. Java methods can return more than one value
To call the method startCall() with the number 4432 and 3 retries what would
you write in the main() method?
Remember to put a ; at the end of the statement and space after , .
startCall(4432,3);
Answer

How is the return value declared in a method?

a. By the data type and the variable name following the method name
b. By the data type alone before the method name
c. By the data type and variable names in parenthesis
d. By the data type alone after the method name
A value supplied to a tethod is known as a(n)

a. argument
b. parameter
The return value from a method must always match the declared return type.

True
False

Question text
Write a method with empty body for the following description.
The method must be called calculateFinalExam. The method must return a
double. The method accepts 3 parameters:
1. the studentId which must be an integer
2. the studentName which must be a String
3. the testScore which must be a double.
The wording must be exact and correct! Don't put space after the names.
double
public static Answer
calculateFinalExam
Answer
(
Answer
int studentId
Answer
String studentName
, Answer
double testScore
,Answer
) {}
What word is missing below? (fill the gap).
Write a method declaration called increaseTemperature which takes 2
integers as a formal parameters. The two parameters represent the upper
and lower targets. The method returns the different between the upper and
lower targets as an integer.
int
public staticAnswer
increaseTemperature(int upper, int lower) {

return upper - lower;


}
The following code in the main is valid:
public static void main(String [] args) {
int value;
value = createGameCharacter();
// rest of program
}

public static void createGameCharacter() {// }


Select one:
True
False
What is the return type of a method that does not returns any value?
Select one:
a. float
b. void
c. double
d. int

If the objects of a class are arranged into their natural order, then if object L is left of object R
what is true? Select one:

e. L.compareTo(R) is positive
f. R.compareTo(L) is negative Incorrect
g. L.compareTo(R) is zero
h. L.compareTo(R) is negative

What is ZURICH.compareTo(cairo)

d. a. zero
e. b. a positive integer
f. d. a negative integer

What is the value of (new Integer(5)).compareTo( new Integer(8) )?


a. a positive integer
b. a negative integer
c. 0
d. unpredictable