SE 2205a (Unit 1-Part 2) Flashcards

Generic Data Types

1
Q

What is a generic class?

A

It can be created to generate a family of classes

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

What is the key benefit of generics?

A

To enable errors to be detected at compile error rather than at runtime

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

What do generic methods introduce?

A

They introduce their own type of parameters

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

What is a bounded generic type?

A

A generic type that can be specified as a subtype of another type is a bounded one

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

What is the first restriction on generics?

A

Cannot create an instance of a generic type (i.e. new T())

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

What is the second restriction on generics?

A

Generic array creation is not allowed (i.e. new T[100])

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

What is the third restriction on generics?

A

A generic type parameter of a class is not allowed in a static context

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

What is the fourth restriction on generics?

A

Exception classes cannot be generic

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

What is an ArrayList?

A

It is a generic class

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

What does the ArrayList class allow?

A

Allows object storage, not primitive-type data storage

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

How is the ArrayList different from an array?

A

-It automatically expands when a new item is added
-It automatically shrinks when items are removed

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

What is the default capacity of an ArrayList?

A

10 items

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

What are the three ways of printing items from an ArrayList?

A

-for loop
-enhanced for loop
-the toString()

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