gpt4 book ai didi

actionscript-3 - ActionScript 3 覆盖方法 + 提高可见性

转载 作者:行者123 更新时间:2023-12-02 05:20:17 24 4
gpt4 key购买 nike

当我扩展一个类时,我想覆盖方法并更改它们的可访问性,就像 protected 方法应该在某个类中公开一样。当我编译它时说:“不兼容的覆盖”。我无法降低也无法提高可见度。

减少没有意义,我不需要它,但我能够在 Java 中增加方法可见性。为什么不在 ActionScript 3 中?

public class OldClass
{
protected function doStuff() : void
{}
}
public class NewClass extends OldClass
{
override public function doStuff() : void
{}
}

我做错了什么吗?

最佳答案

不,你没有做错任何事。这就是语言的工作原理。来自documentation (强调):

Static methods are not inherited and cannot be overridden. Instance methods, however, are inherited by subclasses and can be overridden as long as the following two criteria are met:

  • ...

  • The override method must have the same level of access control as the base class method. Methods marked as internal have the same level of access control as methods that have no access control specifier.

  • The override method must have the same number of parameters as the base class method.

  • The override method parameters must have the same data type annotations as the parameters in the base class method.

  • The override method must have the same return type as the base class method.

关于actionscript-3 - ActionScript 3 覆盖方法 + 提高可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13986021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com