Method does not override method from its superclass
时间: 2024-06-01 12:11:13 浏览: 9
This error message typically occurs when you try to override a method in a subclass that does not have a corresponding method in its superclass.
For example, if you create a subclass of a superclass that does not have a method named "foo", and then try to override a method called "foo" in the subclass, you will see this error message.
To fix this error, make sure that the method you are trying to override has the same name, return type, and parameter list as the method in the superclass. If the method does not exist in the superclass, consider adding it to the superclass or renaming the method in the subclass.
相关问题
method does not override method from its superclass
这个错误通常是由于子类试图覆盖其父类中不存在的方法而引起的。在Java中,如果子类想要重写其父类的方法,那么子类必须使用与父类相同的方法签名(即具有相同的方法名称、参数类型和返回类型)。如果子类中的方法签名与父类中的方法签名不匹配,就会出现“method does not override method from its superclass”的错误。
要解决这个问题,你需要检查你的子类方法签名是否与父类方法签名匹配。如果不匹配,你可以更改子类方法的名称、参数类型或返回类型,以使其与父类方法匹配。如果你确定你的子类方法应该覆盖父类方法,但是你不确定方法签名是否正确,你可以使用@override注解来确保方法签名正确。
报错:Method does not override method from its superclass
这个错误通常是因为你的子类中的方法签名与父类中的方法签名不匹配导致的。你需要检查一下子类中的方法签名是否正确地重写了父类中的方法。
另外,还有可能是你的子类中的方法访问修饰符不正确,例如,你在子类中将一个方法声明为 private,但是在父类中这个方法是 public 的,这也会导致这个错误的发生。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)