Debian Codegraph @

src/test/01-Basic/278-super-single.ck

raw
1 // name: super-3-singlelevel.ck
2 // desc: more comprehensive usage example of `super` keyword
3 // in single level of inheritance
4 // author: Niccolo, Fall 2025
5
6 class Parent
7 {
8 1 => int parent_var;
9
10 fun Parent()
11 {
12 <<< "Parent ctor" >>>;
13 }
14
15 fun void overridden()
16 {
17 <<< "Parent overridden" >>>;
18 }
19
20 fun void not_overridden()
21 {
22 <<< "Parent not_overridden" >>>;
23 }
24 }
25
26 class Child extends Parent
27 {
28 fun Child()
29 {
30 <<< "Child ctor" >>>;
31 }
32
33 fun void test()
34 {
35 <<< "Test start" >>>;
36
37 // call parent contructor - seems to be allowed by ChucK so it should work with super as well
38 <<< "super.Parent() - expecting parent ctor" >>>;
39 super.Parent();
40 // should call parent version of not_overridden - need to test in 3 generation setup
41 <<< "super.not_overridden() - expecting parent not_overridden" >>>;
42 super.not_overridden();
43 // should call parent version of overridden
44 <<< "super.overridden() - expecting parent overridden" >>>;
45 super.overridden();
46 // should call child version of overridden
47 <<< "this.overridden() - expecting child overrridden" >>>;
48 this.overridden();
49
50 // should access the child variable (same as this)
51 <<< "super.parent_var - expecting 1" >>>;
52 <<< super.parent_var >>>;
53
54 <<< "test complete" >>>;
55 }
56
57 fun void overridden()
58 {
59 <<< "Child overridden" >>>;
60 }
61
62 fun void not_override()
63 {
64 <<< "Child not_override" >>>;
65 }
66 }
67
68 Child child;
69 child.test();