Test 2 Prep 3 Questions Flashcards

1
Q

True/False: A class can only implement one interface.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Java interfaces are allowed to have _ instance variables?

A

Zero, although can have final variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True/False: The following will compile:

Comparable aBlock = new String();

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the visibility of the method below?

public interface myChoice {
    void shoutOutLoud(T phrase);
}
A

public

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Will the following compile?

public interface myName {
    String whatsMyName(String name) {
        return "Harsh";
    }
}
A

Will not compile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True/False: ArrayList implements at least one interface.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
True/False: The following code will compile:
List myNums = new ArrayList();
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True/False: The following will compile:

Comparable aBlock = new Comparable();

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What line causes the following code to fail to compile?

List myInts = new ArrayList();
myInts.add(4);
myInts.add(new Integer(42));
int firstInt = myInts.get(0);
A

The last line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given an interface Gradeable and a class named CS Test, write the class declaration (first line) for the CSTest so that CSTest will use Gradeable.

A
public class CSTest implements Gradeable, Comparable,... {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly