-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMultipleInterfaceVariants31.java
More file actions
44 lines (35 loc) · 976 Bytes
/
MultipleInterfaceVariants31.java
File metadata and controls
44 lines (35 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package thinkinginjava.generics;
// TIJ4 Chapter Generics, Exercise 31, page 697
// Remove all generics from MultipleInterfaceVariants.java and modify
// the code so that the example compiles.
interface Payable2 { float getPay(); }
class Employee2 implements Payable2 {
private float weeklyPay;
public float getPay() {
return weeklyPay;
}
}
class Hourly2 extends Employee2 implements Payable2{
public String name;
protected float hourlyPay;
public int hoursWorked;
Hourly2(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) {
Hourly2 h = new Hourly2("Joe", 50.00f, 40);
h.getPay();
System.out.println("=============");
Payable2 p = new Hourly2("Joe", 50.00f, 40);
p.getPay();
}
}