| 1 |
// name: super-2-skiplevel.ck |
| 2 |
// desc: usage of `super` keyword when functions are overriden every |
| 3 |
// level of the inheritance |
| 4 |
// authors: Nick and Ge, Fall 2025 |
| 5 |
|
| 6 |
// W |
| 7 |
class W |
| 8 |
{ |
| 9 |
// a function |
| 10 |
fun void boo( int i ) { <<< "W", i >>>; } |
| 11 |
} |
| 12 |
|
| 13 |
// child of W |
| 14 |
class X extends W |
| 15 |
{ |
| 16 |
// X does not overrie boo (but X's child Y does override) |
| 17 |
// fun void boo( int i ) { <<< "X", i >>>; super.boo(3); } |
| 18 |
} |
| 19 |
|
| 20 |
// child of X; grandchild of W |
| 21 |
class Y extends X |
| 22 |
{ |
| 23 |
// calling superclass boo from class pre-constructor code |
| 24 |
// FYI this should call W's boo(), skipping X |
| 25 |
super.boo(1); |
| 26 |
|
| 27 |
// overriding boo() |
| 28 |
fun void boo( int i ) { <<< "Y", i >>>; } |
| 29 |
} |
| 30 |
|
| 31 |
// instantiate a Y |
| 32 |
Y y; |
| 33 |
|
| 34 |
// call |
| 35 |
y.boo( 4 ); |