Question 13
Assume you need to write an implementation of a stack that has 3 public methods: push, pop, and peek. Assume your implementation uses an array to store the elements.
Where in the array should you remove the new elements?
Either way - beginning and end are equally good.
Neither - using an array to implement a stack is a bad idea.
At the beginning of the array (index).
Question 14
Assume you need to write a class called Marble. In order to be able to sort all the marbles in your collection, you decide to implement the interface Comparable<T>.
Which of the following code segments should you use to implement that class?
1. public class Marble<Marble> implements Comparable<> {...}
2. public class Marble> Marble implements Comparable<>(...)
3. public Marble> class Marble> implements Comparable<> {...}
4. public class Marble implements Comparable<Marble> {...}
Question 15
Here is a sentence that is supposed to describe the value that is returned by the method compareTo from the interface Comparable<T>:
The method compareTo returns
as this object is less than, equal to, or greater than the specified object.
Fill in the missing part with one of the options below.
a negative integer, zero, or a positive integer
1, 0, or -1
-1, 0, or 1
a positive integer, zero, or a negative integer