Cards from Crash Course Flashcards

1
Q

Can you access List items by position?

A

Yes

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

Can you add items to the end of a list, or in the middle? or the beginnin?

A

Yes

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

Can you replace items on the array at a certain position?

A

Yes

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

Do you access the number of items in a list by .size() or .length()?

A

.size()

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

Does this compile? What is “List”?

A

Yes. An interface.

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

What’s the method used to put items on a List?

A

.add();

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

How would you find something on a list by an index? Which method would you use?

A

.get(0);

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

Why doesn’t this compile?
List names = new ArrayList<>();
names.add(“Jedd”);
names.add(“Lomin”);

String name =names.get(0);

A

The object in names may not always be a string, so the compiler will work to prevent you from messing up. If you went List it would work.

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

Will this compile?
List names = new ArrayList<>();
names.add(“Jedd”);
names.add(“Lomin”);

String name = names.get(0);

A

no
names.get(0); may not always be a String so the compiler will not let you do this. If you gave List names a type of String (List names) then you would be fine.

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

What is the classCastException about?

A

It’s when you try to cast something into a data type that it can’t be cast into.

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

Does this work?
List names = new ArrayList<>();
names.add(“Jedd”);
names.add(“Lomin”);

	String name = names.get(0);

	System.out.println(names);
A

yeah that’s fine

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

Does this compile? why or why not?

List numbers = new ArrayList<>();

A

cannot make a list of a primitive

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

Does this compile?
List names = new ArrayList<>();
names.add(“Jedd”);
names.add(“Lomin”);

	String name = names.get(0);

	System.out.println(names);
	System.out.println(names.contains("Jedd"));
A

Yes

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

Under what condition would you not be able to sue the contains() method?

A

If the object doesn’t implement that method.

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

Does this compile?

public static void main(String… strings) {
List names = new ArrayList<>();
names.add(“Jedd”);
names.add(“Lomin”);
System.out.println(getLongNames(names).size());
}

public static List getLongNames(List list){
	List results = new ArrayList<>(list);
	return results;
}
A

Yes. It’s fine. Demonstartes how you can build a list with an argument.

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

Are the error messages from Lambdas sometimes obscure?

A

Yes

17
Q

Can you make a lambda using an interface with more than one abstract method?

A

no

18
Q

What is generalization?

A

The idea that allows you to write code on a general concept, and then have that code work in specializations without having to make any additional changes.

19
Q

What is the difference between interface inheritance and implementation inheritance?

A

Interface inheritance is about fulfilling a promise or contract. What is inherited is an obligation.

Implementation inheritance, or when you extend a class, provides the method along with the code body to provide how the method is to work.

20
Q

What are two examples of interface inheritance?

A

Abstract classes and interfaces