OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library object_super_test; | 5 library object_super_test; |
6 | 6 |
7 /// Simple program creating an object with super constructor invocation. | 7 /// Simple program creating an object with super constructor invocation. |
8 void main() { | 8 void main() { |
| 9 print("Create A instance"); |
9 var a = new A.withArgs(0); | 10 var a = new A.withArgs(0); |
10 print(a.foo); | 11 print(a.foo); |
11 | 12 |
| 13 print("Create B instance"); |
12 var b1 = new B.withSuper(); | 14 var b1 = new B.withSuper(); |
13 print(b1.foo); | 15 print(b1.foo); |
14 print(b1.bar); | 16 print(b1.bar); |
15 | |
16 var b2 = new B(); | |
17 print(b2.foo); | |
18 print(b2.bar); | |
19 } | 17 } |
20 | 18 |
21 class A { | 19 class A { |
22 String foo; | 20 String foo; |
23 | 21 |
24 A() : this.withArgs(0); | |
25 A.withArgs(int i) : foo = fieldInitializer(i, 'A.foo'); | 22 A.withArgs(int i) : foo = fieldInitializer(i, 'A.foo'); |
26 } | 23 } |
27 | 24 |
28 class B extends A { | 25 class B extends A { |
29 String bar; | 26 String bar; |
30 | 27 |
31 B(); | |
32 B.withSuper() | 28 B.withSuper() |
33 : bar = fieldInitializer(0, 'B.bar'), | 29 : bar = fieldInitializer(0, 'B.bar'), |
34 super.withArgs(1); | 30 super.withArgs(1); |
35 } | 31 } |
36 | 32 |
37 String fieldInitializer(int f, String s) { | 33 String fieldInitializer(int f, String s) { |
38 print('$s: $f'); | 34 print('$s: $f'); |
39 return '$s: $f'; | 35 return '$s: $f'; |
40 } | 36 } |
OLD | NEW |