 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
When
you write multiple constructors, sometimes we like
|
|
to
have the contructors call another function to actually
|
|
|
get
the work done (to minimize duplication of code)
|
|
|
| • |
In
C++ we do this by writing named member functions
|
|
|
| • |
In
Java we do this by having one constructor call another
|
|
|
constructor
with a special usage of the this pointer!
|
|
|
|
– |
This
can only happen once within a constructor
|
|
|
|
– |
It
must be the first thing a constructor does
|
|
|
|
list
(int i) { //first constructor which does the real work}
|
|
|
|
list
(int i, int j) {this(i); //calls
the constructor with an int }
|
|