Chapter 9 Flashcards
(19 cards)
What are the four main types of class relationships in Java?
Inheritance (is-a), Aggregation (has-a), Composition (strong has-a), Association (uses-a).
What is aggregation?
A weak ‘has-a’ relationship where the contained object can exist independently of the container.
What is composition?
A strong ‘has-a’ relationship where the contained object cannot exist without the container.
What is the difference between inheritance and aggregation?
Inheritance extends functionality (is-a), while aggregation combines classes (has-a).
How do you identify a class in UML?
It’s a rectangle with three sections: class name, fields, and methods.
What does a line with a hollow triangle arrowhead mean in UML?
Inheritance (generalization) — the arrow points to the superclass.
What do arrows with diamonds represent in UML?
Diamonds represent ‘has-a’ relationships:
- Hollow diamond = aggregation
- Filled diamond = composition
In UML, what does +
and -
mean before a member?
+
is public, -
is private.
What is an ArrayList?
A resizable array-like structure that holds objects (not primitives) and grows as needed.
How do you create an ArrayList of Strings?
ArrayList<String> names = new ArrayList<>();
How do you add and remove items in an ArrayList?
.add(value)
, .remove(index)
or .remove(value)
.
How do you access elements and get the size?
.get(index)
, .size()
.
What must you import to use ArrayList?
import java.util.ArrayList;
What is a parameter list in a method?
It’s the list of inputs a method takes, defined inside parentheses.
What’s the difference between parameters and arguments?
Parameters are in the method definition. Arguments are what you pass in during the call.
How do you define a method with parameters?
public void greet(String name, int age)
.
What happens if the argument list doesn’t match the parameter list?
A compile-time error occurs.
What is method overloading?
Having multiple methods with the same name but different parameter lists.
what is a parameter list?
the list of parameters inside the method header