Chapter 7 - Inheritance Flashcards

1
Q

inheritance

A
  • define a new class (subclass) in terms of how it extends an existing base class (superclass)
  • using keyword ‘extends’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

runtime type vs. compile-time (static) type

A
  • runtime: mentioned in new operation and represented by object returned by method getClass(); remains unchanged
  • static type: type of variable in which a reference to the object is stored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

downcasting

A
  • use instanceOf or getClass() before downcasting a variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

single inheritance

A
  • a given class can only declare to inherit from a single class
  • by default, classes extend Object class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

inheriting fields

A
  • when creating a new object, the object will have a field for each field declaration in its superclasses
  • for fields to be accessible to subclasses, set their access modifiers to protected or use a getter method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

inheriting methods

A
  • methods of a superclass are applicable to instances of a subclass
  • can override methods
  • can use super keyword to call method from superclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

abstract classes

A
  • cannot be instantiated
  • can have both abstract (no implementation) and regular methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

TEMPLATE METHOD design pattern

A
  • put all common code in the superclass and define some hooks to allow subclasses to provide specialized functionality where needed
  • declare template method to be fine (cannot be overidden by subclasses)
  • the method implemented by subclasses is protected and abstract
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

final classes

A
  • cannot be inherited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly