| 1 |
// name: super-1-simple.ck |
| 2 |
// desc: simple usage of `super` keyword to access parent functions |
| 3 |
// authors: Nick and Ge, Fall 2025 |
| 4 |
|
| 5 |
// a class |
| 6 |
class X |
| 7 |
{ |
| 8 |
// a function |
| 9 |
fun void boo( int i ) { <<< "W", i >>>; } |
| 10 |
} |
| 11 |
|
| 12 |
// another class; a child of X |
| 13 |
class Y extends X |
| 14 |
{ |
| 15 |
// calling superclass boo from class pre-constructor code |
| 16 |
super.boo(1); |
| 17 |
|
| 18 |
// overriding boo() |
| 19 |
fun void boo( int i ) |
| 20 |
{ |
| 21 |
<<< "Y", i >>>; |
| 22 |
// calling superclass boo from within a member function |
| 23 |
super.boo(2); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// instantiate a Y |
| 28 |
Y y; |
| 29 |
|
| 30 |
// call |
| 31 |
y.boo( 4 ); |