Lecture 7B Flashcards

1
Q

When is type compatibility checked?

A

At compile time, before runtime. Java is statically typed. This check is called type checking.

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

When is a variable polymorphic?

A

When it can store references of objects with several different types.

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

Shape s = new Circle(); name the types

A

The static type of s is reference type Shape, the dynamic type of s is reference type Circle. Java determines dynamic type at runtime.

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

When does dynamic dispatch work?

A

Only for overriding methods. Ie Shape s = new Circle(); s.circleMethod() doesn’t work.

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

Interfaces - rules:

A

Only visibility modifier allowed is public, only has abstract methods, only has none or static final fields,

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

What i relationship between class an interface?

A

A weak is-a relationship.

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

How to derive an interce from another interface?

A

Interface1 extends interface2, interface3 {}

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

When to use an interface?

A

To achieve a restricted form of multi-inheritance, to separate public aspects of a class from implementation (an interface is all you need to interact with a class), to demand functionality from several different classes.

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

What are primitive wrapper classes?

A

Integer, Double etc Conversion between primitives and wrappers done automatically by boxing and unboxing.

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