#5 inheritance (2.1 +2.2) Flashcards

(15 cards)

1
Q

override

A
a subclass can override (redefine) methods in the superclass
same name and signature

(uses super() to call the original method)

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

dynamic dispatch/late binding/dynamic method binding

A

overriding, happens during program execution

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

nonstatic: how is overriding determined

A

the type of object (not the reference) determines which method will be called

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

static: how is overriding determined

A

the type of the variable determines which method will be called

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

overriding and privacy

A

subclasses can make overridden methods more private. they cannot make them more public.

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

private things in a superclass

A
subclass cannot directly access private fields and methods in its superclass(es)
CAN THET BE OVERRIDEN? no
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

protected

A

subclasses have access (same package or not)

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

subclasses and super classes can have fields with the same name how

A

you use super. to differentiate between the two. subclass takes precedence. super. only refers to the immediate super class

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

final with overriding

A

final methods cannot be overridden (nor can private, b/c they are implicitly final)

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

final with inheritance

A

final:
cannot be extended (have subclasses)
it’s methods are implicitly final
(string is a java library final class)

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

what can a super class access?

A

only fields and methods in its class (doesn’t know subclass exists)

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

upcasting

A

cast a subclass reference to a superclass reference

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

downcasting

A

cast a superclass reference to a subclass reference

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

cast a car to a vehicle

A

ALWAYS VALID

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

cast a vehicle to a car

A

ONLY IF VEHICLE IS ACTUALLY OF TYPE CAR!

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