【问题标题】:Why I am getting the below error? I interchanged the class names and there was no error为什么我收到以下错误?我交换了类名,没有错误
【发布时间】:2016-07-09 18:30:33
【问题描述】:

Here i changed the base and child classes but still my main class is Overloading

我在 java 8 中执行此操作。我尝试交换类名。当我这样做时,我也改组了主要方法。我没有收到任何错误。这是我遇到错误的唯一情况。我不明白为什么。请帮忙。

【问题讨论】:

  • 你的洗牌有什么理由吗?如果你想知道一个子类可以继承它的超类的成员,但反过来不行,那么你做到了。

标签: java inheritance main


【解决方案1】:

在您的 Eclipse ide 中按 运行配置。确保在主类中写入“Practice.Pervert”

我设法重现了您的问题。如果在此文本字段中写入 Orloading,则会出现完全相同的错误。

【讨论】:

  • 我检查了运行配置。在文本字段中,写着重载。 package Practice; class Pervert { public void nothing() { System.out.println("This is pervert class"); } public static void main(java.lang.String[] args) { // TODO Auto-generated method stub System.out.println("main"); } } public class Overloading extends Pervert{ public void something() { System.out.println("this is overloading"); } } 它正在被执行
  • 准确来说应该是 Practice.Pervert。
  • @AbhilashPadhee 哪个类包含您的主要方法?你想从哪个类获取 main 方法?
  • @Pshemo 主要方法在重载类中。但是在交换子类和父类之后,我不明白为什么它没有抛出任何错误。
  • 因为在你的运行配置中你需要指定另一个类作为主类。当我说运行配置时,我的意思是 Eclise 运行配置,您可以在运行部分找到它。
猜你喜欢
  • 2021-09-04
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多