java - 在 Eclipse 中运行一个 CHILD,其中 PARENT 类具有 main 方法,但 CHILD 类本身只是一个没有 main 方法的类

标签 java eclipse inheritance main-method

//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应用程序。 enter image description here

最佳答案

我通过在 eclipse 中这样做解决了这个问题: 步骤 1 右键单击​​ --> 运行配置

第2步选中复选框-搜索主类时包含继承的主类。

第 3 步 - 现在再次点击“搜索”。您应该能够找到您要查找的子类。

Check the second option

关于java - 在 Eclipse 中运行一个 CHILD,其中 PARENT 类具有 main 方法,但 CHILD 类本身只是一个没有 main 方法的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61806162/

相关文章:

java - Spring单元测试,如何检查方法是否将信息存储在数据库中?

java - 删除方法在 List 接口(interface)迭代器中抛出错误

java - Hibernate - 从多个字段到同一实体的关系

java - DocuSign Rest API - 使用多个 CompositeTemplates 后下载完整的文档

java - Eclipse:同时替换多个不同的正则表达式

c++ - 使用不支持的类型继承 C++ 中的模板类

python - 如何在 Eclipse for Python 中设置远程开发? ( "remote"部分)

eclipse - 如何在 SICSTUS "SPIDER"IDE 中显示变量绑定(bind)?

java - ArrayList 中的 "Duplicate"条目?

C++ RTTI 和派生类