1/* 2 * Copyright (c) 2023-2025 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 16abstract class A { 17 str: string = "A" 18 19 getA():string { 20 return this.str; 21 } 22} 23 24abstract class B extends A { 25 getB():string { 26 return this.str; 27 } 28 29 public get_str(): string { 30 return this.str; 31 } 32 33 public get_super_str(): string { 34 return super.getA(); 35 } 36} 37 38class BB extends B {} 39 40abstract class C extends B { 41 str: string = "C" 42 43 public override get_str(): string { 44 return this.str; 45 } 46 47 public override get_super_str(): string { 48 return super.getB(); 49 } 50} 51 52class CC extends C {} 53 54function main(): void { 55 let b: B = new BB(); 56 let c: C = new CC(); 57 58 assertEQ(b.str, "A") 59 assertEQ(b.get_str(), "A") 60 assertEQ(b.get_super_str(), "A") 61 assertEQ(c.str, "C") 62 assertEQ(c.get_str(), "C") 63 assertEQ(c.get_super_str(), "A") 64 65 assertEQ((b as B).str, "A") 66 assertEQ((b as A).str, "A") 67 assertEQ((b as B).get_str(), "A") 68 assertEQ((b as B).get_super_str(), "A") 69 70 assertEQ((c as C).str, "C") 71 assertEQ((c as B).str, "A") 72 assertEQ((c as A).str, "A") 73 74 assertEQ((c as C).get_str(), "C") 75 assertEQ((c as C).get_super_str(), "A") 76 assertEQ((c as B).get_str(), "C") 77 assertEQ((c as B).get_super_str(), "A") 78} 79