Week 6 Flashcards

1
Q

A general relationship that describes an activity between 2 classes

A

Association

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

How are associations denoted? How do the 2 classes relate?

A

A straight line arrow and direction. They relate through their objects.

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

To communicate between each other, 2 classes must have a link between them. What is this link represented by?

A

Association.

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

What are 2 form of association?

A

Aggregation and composition

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

A relationship where an objects owns a collection of other identical objects

A

Aggregation, also known as a has-a relationship

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

What are some examples of aggregations?

A

Professor has many students, hotel has many suites. One way, reverse not possible

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

T/F - An aggregation relationship is represented by a field in the aggregating class

A

True

Aggregated class
public class Name {}

Aggregating class
public class Student {
private Name name;
private Address address;

}

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

Relationship where a class contains other references to other classes

A

Composition (has-a relationship)

IE. Room has a door, Car has a wheel

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

T/F - Composition is a special cast of aggregation

A

True

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

In __________ a child can exist independently of the parent, in ___________ the child cannot exist independent of the parent

A

Aggregation, composition

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

Composition vs Aggregation, types of association

A

Composition: Strong association
Aggregation: Weak association

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

Inheritance has what type of relationship?

A

is-a relationship

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

the ___class is a specialization of the _____class, and has characteristics of it

A

subclass, superclass

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

Can a subclass be treated like a parent type?

A

Yes. A motorcycle is-a vehicle. A car is-a vehicle.

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

Can every class be inherited?

A

No, final classes cannot.

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

Can a class inherit from more than one class ?

A

No, Java does not support multiple inheritance

17
Q

What rules are there pertaining to the super keyword?

A

Super() can only be used inside the subclass constructor and it must be the first statement.

18
Q

Can any other method in the subclass call the superclass constructor? (super())

A

No

19
Q

Do we always need to call the superclass constructor when we instantiate a subclass object? Why?

A

Yes. When a subclass object is instantiated the subclass object must also automatically execute one of the constructors of the superclass.

Otherwise you wouldn’t be able to inherit anything.

20
Q

How do you prevent a method in a class from being overridden in a subclass?

A

There’s a number of ways.
1. Use a static method
2. Make a private access modifier
3. You can prevent a method being overridden by subclasses by declaring it as final.

Something about default modifiers but that’s eh

21
Q

Overload vs override

A

1.
Override = methods of same name and signature
Overload = methods of same name, different signature

  1. Chaining can be achieved using the “this” keyword, while subclasses may call super classes using the “super” keyword
  2. Constuctors can be overloaded, but constructors cannot be inherited.
22
Q

Overloading occurs at _______-time, while overriding occurs at ___-___

A

compile time, run time

23
Q

What does compile time denote? What does run time denote? How does the former relate to static?

A

Compile time denotes the time of program
compilation, Run-time denotes the time of program
execution

Static refers to anything created at compile time, and remains