22 lines
372 B
Java
22 lines
372 B
Java
|
package exercises.ex_j;
|
||
|
|
||
|
class Spoon {
|
||
|
private Diner owner;
|
||
|
|
||
|
public synchronized Diner getOwner() {
|
||
|
return owner;
|
||
|
}
|
||
|
|
||
|
public Spoon(Diner d) {
|
||
|
owner = d;
|
||
|
}
|
||
|
|
||
|
public synchronized void setOwner(Diner d) {
|
||
|
owner = d;
|
||
|
}
|
||
|
|
||
|
public synchronized void use() {
|
||
|
System.out.printf("%s has eaten!", owner.getName());
|
||
|
}
|
||
|
}
|