【发布时间】:2020-08-02 06:01:27
【问题描述】:
//Package in which I have both the Parent and the Child class
package learningJava;
public class MainMethodDemoParent
{
//Main method of the parent class
public static void main(String... args)
{
System.out.print("This is the Parent class");
}
}
//Child class which extends the Parent class
package learningJava;
public class MainMethodDemoChild extends MainMethodDemoParent
{
}
当我尝试运行没有main方法但与父类在同一个包中的子类以便我可以访问父类的main方法时,在Eclipse中没有RUN选项Child 类是一个 java 应用程序。
【问题讨论】:
-
我讨厌成为那个评论者,但有没有理由这样做。要么运行父方法,要么在子进程中创建另一个
main来执行其他操作。 -
如果我是你,我不会恨我,感谢你的评论,但有什么方法可以在 Eclipse 中克服这个问题?通过 CMD,您可以在同一个 .java 文件中编译具有子类的父类。因此,创建了两个 .class 文件,一个为父级,另一个为子级。在执行 Child 类时,您将获得输出。但是如何在 Eclipse 中实现呢?
标签: java eclipse inheritance main-method