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
抛出异常