class not found:在eclipse中成功运行但在命令提示符下抛出异常

时间:2013-08-27 04:37:21

标签: java

import java.util.*;

interface Payable {
    public void getAmount(int x);
}

class HEmployee implements Payable {
    public void getAmount(int x) {
        System.out.println("Amount paid to Hourly employee is Rs.::" + (x * 120));
    }
}

class WEmployee implements Payable {
    public void getAmount(int x) {
        System.out.println("Amount paid to Weakly employee is Rs.::" + (x * 820));
    }
}

class J40 {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        Payable refer;
        HEmployee h1 = new HEmployee();
        System.out.println("Enter the Hourly employee worked Hours::");
        int h = s.nextInt();
        refer = h1;
        refer.getAmount(h);
        WEmployee w1 = new WEmployee();
        System.out.println("Enter Weakly employee worked Hours::");
        int w = s.nextInt();
        refer = w1;
        refer.getAmount(w);
    }
}

eclipse 中成功运行,但在命令提示符下抛出异常。

按名称J40.java

保存

javac J40.java成功。

java J40抛出异常

2 个答案:

答案 0 :(得分:0)

我可以通过命令提示符运行代码而不会出现任何异常

enter image description here

我没有修改过。

答案 1 :(得分:0)

我设法在Eclipse和命令提示符下运行代码。我已将每个接口和类划分为单个文件,import java.util.*;应该在J40类中。

以下是我运行的命令行。

C:\Test>javac J40.java

C:\Test>java J40
Enter the Hourly employee worked Hours::
12
Amount paid to Hourly employee is Rs.::1440
Enter Weakly employee worked Hours::
2
Amount paid to Weakly employee is Rs.::1640