multipleinterfacevariants31.java

来自「Thinking In Java 第四版练习题答案」· Java 代码 · 共 36 行

JAVA
36
字号
// generics/MultipleInterfaceVariants31.java
// TIJ4 Chapter Generics, Exercise 31, page 697
// Remove all generics from MultipleInterfaceVariants.java and modify
// the code so that the example compiles.

interface Payable { float getPay(); }

class Employee implements Payable {
	private float weeklyPay;
	public float getPay() {
		return weeklyPay;
	}		
} 

class Hourly extends Employee {
	public String name;
	protected float hourlyPay;
	public int hoursWorked;
	Hourly(String s, float pay, int hours) {
		name = s;
		hourlyPay = pay;
		hoursWorked = hours;
	}
	public float getPay() {
		System.out.println("Pay " + name + 
			" $" + hourlyPay * hoursWorked);
		return hourlyPay * hoursWorked;	
	}
}

public class MultipleInterfaceVariants31 {
	public static void main(String[] args) {
		Hourly h = new Hourly("Joe", 50.00f, 40);
		h.getPay();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?