Lecture 7A Flashcards

1
Q

What does transitive mean?

A

In Java inheritance is transitive. If class X extends class Y and class Y extends class Z, then class X also extends class Z. More: Class X is derived and inherits from class Y. Class Y generalizes class X.

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

A subclass inherits all fields and methods from its superclass except…

A

Constructors and private fields.

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

Why only use instanceof the odd time?

A

It doesn’t confirm to the principles of static typing.

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

When can a method not be overridden?

A

With a method with more restrictive accessibility. Also can’t override private method. Also, a static method cannot be overridden. If a subtype does define a static method with same signature as superclass then both coexist. Which method is called depends on compile-time type of the object.

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

How to forbid overriding of method?

A

Use Keyword final.

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

How to invoke overriden method?

A

Use keyword super.

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

When is overriden resolved?

A

At runtime using a mechanism called dynamic dispatch.

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

Can you declare a field in subclass with same name as field in superclass?

A

Yes. But it is not overriding. Both co-exist in subclass instance but the field declared by the subclass shadows/hides the superclass field. Super.fieldname to access it again.

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

If an explicit super class constructor call is missing what happens?

A

Java inserts a call super() at the beginning of your subclass constructor, but only if there is a zero parameter constructor

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

What is constructor chaining?

A

The superclass highest in the hierarchy gets processed first, then the next and so on.

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

What is inheritance hierarchy?

A

Multiple classes related by inheritance, ie an is-a relationship

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