Kurs:Informatik I/T6

Aus Wikiversity
Zur Navigation springen Zur Suche springen

T6 - Collections and Abstract Data Types[Bearbeiten]

1 In order to resize an array (e.g. if you need a longer one), you can Choose at least one answer.

assign a greater value to its length attribute.
assign the entire array to another array variable of greater size.
create a larger array, copy the elements into it, and assign it to the original array variable.

2 Given the following definitions:

interface XInter {

public void m1() ;
public void m2() throws XException;

}

class XException extends Exception { }

class YExecption extends RuntimeException { }


Please mark the correct statements:

An implementation of m2 may throw a YExeption.
An implementation of m1 may throw a YException.
An implementation of m1 must throw an XExeption.
An implementation of m2 must not throw an XExeption.
An implementation of m1 must not throw an XExeption.
An implementation of m2 must throw an XExeption.

3 Please mark the correct statements:

An Iterator is an object.
An Iterator is a method.
A collection can have several iterators at a time.
An Iterator needs to be updated whenever the collection it is attached to is updated.
Iterators are standard types in the Java Collection Framework.
Iterators exist only for arrays.

4 Please mark the correct statements:

If the application contains an import statement importing a package, the package is implicitly included in the classpath.
To make a class visible for an application, the folder above its package folder subtree has to be in the classpath.
All classes belonging to the same package must be stored in the same file.
To make a class visible for an application, its package folder has to be in the classpath.
The standard library packages java and javax are implicitly included in the classpath.
A class has to be stored in a folder subtree which corresponds to the package structure.

5 Please mark the correct statements:

The number of array elements varies over time. initially, it is 0.
You CANNOT assign simple variables to array elements like myList[7] = a;
All elements of an array must have the same type.
myList[0] selects the first element of an array myList.
You CANNOT assign array elements to array elements, like myList[4] = mylist[9];
myList.lastIndex is the highest index of an array myList.
myList.length yields the number of elements of an Array myList.
myList[myList.length] selects the last element of an array myList.
myList(0) selects the first element of an array myList.

6 Which members of an ADT should be private?

Methods used to implement the interface methods (procedures).
Attributes
Local variables inside methods
Interface methods, i.e. methods specified by the implemented interface.
Constructors

7 Please mark the correct statements:

Collections are always sorted.
Sorting requires a transitive comparison operation between elements.
Arrays are always sorted.
Removing an element from a sorted array is a complex operation.
A sorted list or array allows efficient element search.
Every array can be sorted.
Inserting an element into a sorted array is a complex operation.

8 Please mark the correct statements:

A stack can be implemented using a queue.
Stack is the opposite of queue.
Stack is the opposite of list.
Stack is a synonym of queue.
Stack is a synonym of list.
A stack can be implemented using a list.
A stack can be implemented using an array.
A stack follows the LIFO scheme.
Stack is a synonym of array.
A stack follows the FIFO scheme.

9  Let a class CL be included in a package p which is included in p0.

 Please mark the correct statements:

The fully qualified name of CL is p.p0.CL
All classes in the standard packages java and javax are implicitly imported.
All classes of the package java.lang are implicitly imported.
The package statement has to be the first line of a java file.
The fully qualified name of CL is p0.p.CL
A class can be used by its fully qualified name without an import statement.
To use a class which is in a package, you must import the class or the entire package.
CL must either be stored in a folder subtree p0->p->CL.java, or contain a package statement.
If a class is not in the classpath, an import statement is required in order to use the class.
Import has no runtime semenatics; it only allows using classes by their class names instead of their fully qualified names.