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 16class A_class { 17 field: number = 1234 // Not visible for the local class 18 method (parameter: number) { 19 let local: string = "instance local" 20 21 interface LocalInterface { 22 method (): void 23 field: string 24 } 25 26 class LocalClass implements LocalInterface { 27 override method () { 28 console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local ) 29 assert(this.field == "`instance method instance field value`") 30 assert(parameter == 42) 31 assert(local == "instance local") 32 33 } 34 field: string = "`instance method instance field value`" 35 static s_method () { 36 console.log ("Static field = " + LocalClass.s_field) 37 assert(LocalClass.s_field == "`instance method class/static field value`") 38 } 39 static s_field: string = "`instance method class/static field value`" 40 } 41 42 let lc: LocalInterface = new LocalClass 43 lc.method() 44 LocalClass.s_method() 45 } 46 47 static s_method (parameter: number) { 48 let local: string = "class/static local" 49 interface LocalInterface { 50 method (): void 51 field: string 52 } 53 54 class LocalClass implements LocalInterface { 55 override method () { 56 console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local) 57 assert(this.field == "`static method instance field value`") 58 assert(parameter == 72) 59 assert(local == "class/static local") 60 } 61 field: string = "`static method instance field value`" 62 static s_method () { 63 console.log ("Static field = " + LocalClass.s_field) 64 assert(LocalClass.s_field == "`static method class/static field value`") 65 } 66 static s_field: string = "`static method class/static field value`" 67 } 68 let lc: LocalInterface = new LocalClass 69 lc.method() 70 LocalClass.s_method() 71 } 72} 73 74function main() : int 75{ 76 A_class.s_method(72); 77 78 let a = new A_class(); 79 a.method(42) 80 81 return 0; 82} 83