Unit 4 JAVA inheritance Flashcards

1
Q

How to inherit in java?

A

using keyword extends.

class B extends A{}

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

Java Inheritance:

A

A subclass can have only one superclass.

No class can be superclass of itself.

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

Member Access and Inheritance

A
Although a subclass includes all of the members of its
superclass, it cannot access those members of the
superclass that have been declared as private.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

super

A

always refers to superclass.

supper.member

also, helps incase of same name causing hiding

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

Multilevel inheritance

super()

A

super() always refers to the constructor in the closest superclass.

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

Order of constructors in the class hierarchy:

make sense of it, reason it?

A
The answer is that in a class hierarchy,
constructors complete their execution in order of derivation,
from superclass to subclass.

A super to B super to C

A’s constructor first then B’s then C’

If you think about it, it makes sense that constructors
complete their execution in order of derivation. Because a
superclass has no knowledge of any subclass, any
initialization it needs to perform is separate from and
possibly prerequisite to any initialization performed by the
subclass. Therefore, it must complete its execution first.

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

Method overriding:

A
when a method in a subclass has the
same name and type signature as a method in its superclass,
then the method in the subclass is said to override the
method in the superclass.
When an overridden method is
called from within its subclass, it will always refer to the
version of that method defined by the subclass. The version
of the method defined by the superclass will be hidden.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Will it override or overload?

A

Method overriding occurs only when the names and the
type signatures of the two methods are identical. If they are
not, then the two methods are simply overloaded.

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

Dynamic Method dispatch:

why imp?

A

Dynamic method dispatch is the
mechanism by which a call to an overridden method is
resolved at run time, rather than compile time. Dynamic
method dispatch is important because this is how Java
implements run-time polymorphism.

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

Abstract Class:

need

A

superclass that declares the structure of a given abstraction
without providing a complete implementation of every
method.
a
superclass that only defines a generalized form that will be
shared by all of its subclasses, leaving it to each subclass to
fill in the details

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