1/* 2 * Copyright (c) 2023 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 16declare function print(a0:any, a1?:any):string; 17 18class A { 19 x:number; 20 y:number; 21 22 constructor(x:number, y:number) { 23 this.x = x; 24 this.y = y; 25 } 26 27 foo() { 28 print("A foo"); 29 } 30 31 bar() { 32 print("A bar"); 33 } 34 35 get t():string { 36 return this.constructor.name; 37 } 38 39 set t(str:string) { 40 print(str); 41 } 42 43} 44 45class B extends A { 46 z:string; 47 constructor(x:number, y:number, z:string) { 48 super(x, y); 49 this.z = z; 50 } 51 52 foo() { 53 print("B foo"); 54 } 55} 56 57function testVtable(o:A) { 58 print(o.x); 59 print(o.y); 60 o.foo(); 61 o.bar(); 62 print("constructor.name:", o.t); 63 o.t = "setter"; 64} 65 66let a = new A(1, 2); 67testVtable(a); 68 69let b = new B(3, 4, "BBBB"); 70testVtable(b); 71print(b.z); 72