当前位置: 首页 > 知识库问答 >
问题:

错误:在类MyPackage.Inheritage中找不到Main方法

黄浩涆
2023-03-14
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);
    }
}

嗨。我刚到爪哇。我正试图写一个继承程序,得到这个错误。

错误:在类myPackage.inheritage中找不到Main方法,请将Main方法定义为:public static void Main(string[]args)或JavaFX应用程序类必须扩展JavaFX.application.application

共有1个答案

方兴旺
2023-03-14

尝试将main方法移到继承类中,如下所示:

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;
}
 类似资料: