1/* 2 * Copyright (c) 2023-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 classVal: double = 1.1; 17 18class A { 19 public static classVal: int = 42; 20 private readonly instanceVal: int; 21 22 constructor(val: int) { 23 this.instanceVal = val; 24 } 25 26 public final getInstanceVar(): int { 27 A.classVal++; 28 classVal++; 29 return this.instanceVal; 30 } 31} 32 33final class B extends A { 34 constructor() { 35 super(69); 36 B.classVal++; 37 } 38} 39 40function main(): void { 41 classVal = 1.1; 42 A.classVal = 42; 43 assert A.classVal == 42; 44 const b = new B(); 45 assert A.classVal == 43; 46 assert classVal == 1.1; 47 assert b.getInstanceVar() == 69; 48 assert classVal == 2.1; 49 assert A.classVal == 44; 50} 51