9 - Inheritance Flashcards

1
Q

Inheritance

A

is the process of deriving a new class from an existing one

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

One purpose of inheritance is …

A

to reuse existing software

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

Inheritance creates an …

A

is-a relationship between the parent and child classes.

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

Extends

A

Java keyword to indicate that a new class is being derived from an existing class.

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

Protected

A

allows derived classes to reference it. Provides encapsulation that permits inheritance.

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

Super

A

used in a class to refer to its parent class such as a class’s constructor.

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

single inheritance

A

Java’s approach to inheritance is called single inheritance, meaning a derived class can only have one parent.

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

A child class can override(redefine) …

A

the parent’s definition of an inherited method. Must have the same name and same signature.

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

Shadow variable

A

if a variable of the same name is declared in a child class.

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

class hierarchy

A

A child of one class can be the parent of one or more other classes

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

Common features should be located as high …

A

in a class hierarchy as is reasonable possible.

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

Object class

A

All Java classes are derived, directly or indirectly, from the Object class.

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

What methods are inherited by every class in a Java program?

A

toString

equals

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

An abstract class cannot …

A

be instantiated. It represents a concept on which other classes can build their definitions. They are like placeholders for all derived classes.

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

Abstract children and parent relationship…

A

A class derived from an abstract parent must override all of its parent’s abstract methods, or the derived class will also be considered abstract.

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

Inheritance can be applied to interfaces …

A

so that one interface can be derived from another.

17
Q

Private members are inherited by the child class…

A

but cannot be referenced directly by name. They may be used indirectly, however.

18
Q

Inheritance: Every derivation should be an …

A

is-a relationship. The child should be a more specific version of the parent.

19
Q

Inheritance: Design a class hierarchy to capitalize…

A

on reuse and potential reuse in the future.

20
Q

Inheritance: Push _______ as high in the class hierarchy as possible.

A

common features

21
Q

Inheritance: Override methods as appropriate….

A

to tailor or change the functionality of a child.

22
Q

Inheritance: Add new variables to the child class as needed but dont….

A

shadow(redefine) an inherited variable.

23
Q

Inheritance: allow each class to…..

A

manage its own data. Therefore, use the super reference to invoke a parent’s construction and to call overridden versions of methods if appropriate.

24
Q

Inheritance: Use interfaces to…

A

create a class that serves multiple roles (simulating multiple inheritance).

25
Q

Inheritance: override general methods such as…

A

toString and equals appropriately in child classes so that the inherited version don’t cause unintentional problems later.

26
Q

Inheritance: Use visibility modifiers carefully to …

A

provide the needed access in derived classes without violating encapsulation.

27
Q

final

A

keyword that can be used to restrict in heritance and prevents it from being overridden in other classes.