You are on page 1of 5

Course: Easy-to-follow Java programming

The quiz questions


Answer the questions below to review what you have learned in Video 12. You will
find the right answers after the questions in the solution part.

1. Generics is…

… a tool for creating objects that are good for everything.

… for creating classes and methods with type parameters.

… a type from Collection Framework.

… a variable whose name is T.

2. What can be a type parameter?

class

primitive type

interface

array

method

variable

Duckademy IT courses – www.duckademy.com


3. Which generic object instantiation is used in which Java version?
(Before Java 5; Java 5 and 6; Java 7 onwards)

List<String> list = new


ArrayList<>();

List<String> list = new


ArrayList<String>();

List list = new ArrayList();

4. String extends Object, therefore List<String> … List<Object>.

contains

extends

has no inheritance connection with

is a superclass for

overrides

5. What does it mean: ? super Integer?

All objects can be used whose class is a superclass for Integer.

All objects can be used whose class is a subclass for Integer.

Only Integer objects can be used.

All objects can be used, super is only for documentation purposes.

The type user has to have a name that contains ”super” and
”Integer” word fragments.

6. What does it mean: ? extends Integer?

All objects can be used whose class is a superclass for Integer.

All objects can be used whose class is a subclass for Integer.

Only Integer objects can be used.

All objects can be used, extends is only for documentation purposes.

The type user has to have a name that contains ”extends” and
”Integer” word fragments.

Duckademy IT courses – www.duckademy.com


7. What will be T and R when you call the following method:
public static <T> T generate(T source) {…}
with the invocation:
R ret = generate(“John Doe”);

T will be String, R can be Object.

T will be Object, R will be String.

T will be Object, R can be Object.

T will be String, R can be anything

T will be String, R can be String.

Duckademy IT courses – www.duckademy.com


----------------------------------------------------------------------------------------------------------------

The answers

1. Generics is…

… a tool for creating objects that are good for everything.

X … for creating classes and methods with type parameters.

… a type from Collection Framework.

… a variable whose name is T.

2. What can be a type parameter?

X class

primitive type

X interface

X array

method

variable

3. Which generic object instantiation is used in which Java version?


(Before Java 5; Java 5 and 6; Java 7 onwards)

List<String> list = new Java 7 onwards


ArrayList<>();

List<String> list = new Java 5 and 6


ArrayList<String>();

List list = new ArrayList(); Before Java 5

4. String extends Object, therefore List<String> … List<Object>.

contains

extends

X has no inheritance connection with

is a superclass for

overrides

Duckademy IT courses – www.duckademy.com


5. What does it mean: ? super Integer?

X All objects can be used whose class is a superclass for Integer.

All objects can be used whose class is a subclass for Integer.

Only Integer objects can be used.

All objects can be used, super is only for documentation purposes.

The type user has to have a name that contains ”super” and
”Integer” word fragments.

6. What does it mean: ? extends Integer?

All objects can be used whose class is a superclass for Integer.

X All objects can be used whose class is a subclass for Integer.

Only Integer objects can be used.

All objects can be used, extends is only for documentation purposes.

The type user has to have a name that contains ”extends” and
”Integer” word fragments.

7. What will be T and R when you call the following method:


public static <T> T generate(T source) {…}
with the invocation:
R ret = generate(“John Doe”);

X T will be String, R can be Object.

T will be Object, R will be String.

T will be Object, R can be Object.

T will be String, R can be anything

X T will be String, R can be String.

Duckademy IT courses – www.duckademy.com

You might also like