1/* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16let results : int[] = [0,0,0]; 17let index : int = 0; 18 19class A { 20 constructor() { 21 results[index++] = 1; 22 } 23} 24 25class B extends A { 26 constructor() { 27 super(); 28 results[index++] = 2; 29 } 30} 31 32class C extends B { 33 constructor() { 34 results[index++] = 3; 35 } 36} 37 38final class D extends C {} 39 40function main() : void { 41 results = [0, 0, 0]; 42 index = 0; 43 44 let a = new A(); 45 assert (results[0] == 1 && results[1] == 0 && results[2] == 0 && index == 1); 46 47 results = [0,0,0,0]; 48 index = 0; 49 let b = new B(); 50 assert (results[0] == 1 && results[1] == 2 && results[2] == 0 && index == 2); 51 52 results = [0,0,0,0]; 53 index = 0; 54 let c = new C(); 55 assert (results[0] == 1 && results[1] == 2 && results[2] == 3 && index == 3); 56 57 results = [0,0,0,0]; 58 index = 0; 59 let d = new D(); 60 assert (results[0] == 1 && results[1] == 2 && results[2] == 3 && index == 3); 61} 62