1/* 2 * Copyright (c) 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 16interface inter { 17 get my_field (): int; 18 set my_field(param: int); 19 20 get_field(): int; 21} 22 23class A implements inter { 24 my_field: int = 3; 25 26 get_field(): int { 27 assert false; 28 return 1; 29 } 30} 31 32class B extends A{ 33 laca: int = 1; 34 get my_field (): int{return this.laca} 35 set my_field(param: int) { 36 this.laca = param; 37 } 38 39 get_field(): int { 40 return this.laca; 41 } 42} 43 44function main() { 45 let a0: A = new A(); 46 assert a0.my_field == 3; 47 48 let a1: inter = new A(); 49 assert a1.my_field == 3; 50 a1.my_field = 5; 51 assert a1.my_field == 5; 52 53 let a2: inter = new B(); 54 assert a2.my_field == a2.get_field(); 55 a2.my_field = 2; 56 assert a2.get_field() == 2; 57 assert a2.my_field == a2.get_field(); 58} 59