ActionScript 3 方法覆盖
示例
当您extend使用类时,可以override使用override关键字在继承的类中定义方法:
public class Example {
public function test():void {
trace('It works!');
}
}
public class AnotherExample extends Example {
public override function test():void {
trace('It still works!');
}
}例:
var example:Example = new Example(); var another:AnotherExample = new AnotherExample(); example.test(); //输出:有效! another.test(); //输出:仍然有效!
您可以使用super关键字从继承的类中引用原始方法。例如,我们可以将的主体更改为:AnotherExample.test()
public override function test():void {
super.test();
trace('Extra content.');
}导致:
another.test(); //输出:有效!
//额外的内容。重写类的构造函数有点不同。该override关键词被省略和访问继承的构造与简单地完成super():
public class AnotherClass extends Example {
public function AnotherClass() {
super(); //在继承的类中调用构造函数。
}
}您还可以重写get和set方法。
热门推荐
10 过年拜年祝福语大全简短
11 情侣520的祝福语简短
12 公司拍摄祝福语大全简短
13 虎年喝酒拜年祝福语简短
14 二零二一年祝福语简短
15 圣诞贺卡祝福语简短高级
16 大班女孩开学祝福语简短
17 立春祝福语简短微信
18 经典新婚祝福语简短英文