首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:在类myPackage.inheritance中找不到主要方法

错误:在类myPackage.inheritance中找不到主要方法
EN

Stack Overflow用户
提问于 2015-12-10 06:45:09
回答 2查看 1.9K关注 0票数 1
代码语言:javascript
复制
package myPackage;

public class inheritance {
     int salary = 50000;
}

class worker extends inheritance {
    int bonus = 10000;

    public static void main(String[] args) {
        worker obj1 = new worker();
        System.out.println("employee salary is" + obj1.salary);
        System.out.println("employee bonus is" + obj1.bonus);
    }
}

嗨..。我对java很陌生。我正在尝试编写一个继承程序并得到这个错误。

错误:在类myPackage.inheritance中找不到主方法,请将主要方法定义为:公共静态空主(String[] args)或JavaFX应用程序类必须扩展javafx.application.Application。

EN

回答 2

Stack Overflow用户

发布于 2015-12-10 06:55:00

尝试将主方法移到inheritance类中,如下所示:

代码语言:javascript
复制
public class inheritance {
    int salary = 50000;
    public static void main(String[] args) {
        worker obj1 = new worker();
        System.out.println("employee salary is" + obj1.salary);
        System.out.println("employee bonus is" + obj1.bonus);
    }
}

class worker extends inheritance {
    int bonus = 10000;
}
票数 0
EN

Stack Overflow用户

发布于 2015-12-10 07:11:30

此错误可能以多种方式发生。

首先,需要澄清您是如何编译和运行程序的。

1.确保java文件放在正确的包(文件夹)中。

2.确保将类文件的位置添加到类路径变量中。

很可能,您的问题将通过将继承类公开来解决。

代码语言:javascript
复制
package myPackage;
class inheritance {
int salary = 50000;}
public  class worker extends inheritance {
int bonus = 10000;
public static void main(String[] args) {
worker obj1 = new worker();
System.out.println("employee salary is" + obj1.salary);
System.out.println("employee bonus is" + obj1.bonus);
}
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34195383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档