Chapter 9 Flashcards

(19 cards)

1
Q

What are the four main types of class relationships in Java?

A

Inheritance (is-a), Aggregation (has-a), Composition (strong has-a), Association (uses-a).

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

What is aggregation?

A

A weak ‘has-a’ relationship where the contained object can exist independently of the container.

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

What is composition?

A

A strong ‘has-a’ relationship where the contained object cannot exist without the container.

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

What is the difference between inheritance and aggregation?

A

Inheritance extends functionality (is-a), while aggregation combines classes (has-a).

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

How do you identify a class in UML?

A

It’s a rectangle with three sections: class name, fields, and methods.

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

What does a line with a hollow triangle arrowhead mean in UML?

A

Inheritance (generalization) — the arrow points to the superclass.

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

What do arrows with diamonds represent in UML?

A

Diamonds represent ‘has-a’ relationships:

  • Hollow diamond = aggregation
  • Filled diamond = composition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In UML, what does + and - mean before a member?

A

+ is public, - is private.

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

What is an ArrayList?

A

A resizable array-like structure that holds objects (not primitives) and grows as needed.

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

How do you create an ArrayList of Strings?

A

ArrayList<String> names = new ArrayList<>();

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

How do you add and remove items in an ArrayList?

A

.add(value), .remove(index) or .remove(value).

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

How do you access elements and get the size?

A

.get(index), .size().

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

What must you import to use ArrayList?

A

import java.util.ArrayList;

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

What is a parameter list in a method?

A

It’s the list of inputs a method takes, defined inside parentheses.

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

What’s the difference between parameters and arguments?

A

Parameters are in the method definition. Arguments are what you pass in during the call.

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

How do you define a method with parameters?

A

public void greet(String name, int age).

17
Q

What happens if the argument list doesn’t match the parameter list?

A

A compile-time error occurs.

18
Q

What is method overloading?

A

Having multiple methods with the same name but different parameter lists.

19
Q

what is a parameter list?

A

the list of parameters inside the method header