Dynamic binding Flashcards

1
Q

What is static binding?

A

the compiler uses the type of variables to do the binding to methods.
compile time feature

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

What is dynamic binding?

A

the decision is made at runtime based on the type of the actual values
run-time feature
exists in both static and dynamic languages.

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

What type of binding used in Java, C#, C++ by default?

A

Java - dynamic binding (encourages OOP)
C# - static binding (strict inheritance by default)
C++ - static binding (because of zero overhead principle).

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

Java: can final methods be invoked via dynamic binding?

A

yes. if the method overrides a non-final method and the static type is of the inherited class (the “parent”).

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

What’s replacement overriding? what are the downsides?

A

The new implementation of an operation replaces the implementation of the operation in the base class

Downsides: disallows code reuse, use case doesn’t justify language limitation.

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

What’s Refinement overriding?

A

The new implementation of an operation refines the implementation of the operation in the base class

Overridden method can be called even though an overriding method exists.

רק מוסיפים לפונקציה המקורית, לכן אין צורך לשכפל קוד וניתן פשוט לקרוא למתודה של ההורה.

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

What are the two refinement strategies?

A

Alpha refinement – child’s method called first, internally calls parent’s method if it wants
Beta refinement – Parent’s method called first, internally calls child’s method if it wants

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

What is const_cast in c++?

A

Purpose: cast away const
Targets: pointers and references
Run-time overhead: none – merely instructs the compiler to allow mutation of the target

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

What is reinterpret_cast in c++?

A

Purpose: instruct the compiler to interpret a bunch of bits differently
Targets: mostly pointer and integral types
Run-time overhead: none

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

What is static_cast in c++?

A

Purpose: cast related types and numeric types
Targets: mostly pointers and numeric types
Run-time overhead: low (no RTTI)
Shortcomings compared to dynamic_cast:
- Can’t down-cast from virtual base class
- No indication whether cast was legal

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

What is dynamic_cast in c++?

A

Purpose: cast to a different sub-object of a polymorphic type
- Non-polymorphic types will yield a compiler error
- Sub-object type usually derived from target’s type, but may be anywhere in the dynamic type’s inheritance
graph

Targets: pointers, references
Run-time overhead: RTTI lookup, possibly noticeable

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

What is C-style cast?

A

does the first C++ cast that is legal within a well defined series of attempts

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