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:
|
public class Flasche <G extends Getränk, V extends Verschluss> {
private G geschmack;
private V verschluss;
public Flasche ( G geschmack, V verschluss) {
this.geschmack=geschmack;
this.verschluss=verschluss;
}
public Verschluss oeffen() throws Nullpointerexception{
if(this.verschluss==null) {
throw new Nullpointerexception ("Flasche schon geöffnet");
}
else {
Verschluss<V>x=this.verschluss;
this.verschluss=null;
}
return x;
}
public Getraenk leeren() throws Nullpointerexception{
if (this.verschluss==null && this.getraenk!=null){
Getraenk x= this.getraenk;
this.getraenk=null;
return x;
}else {
throw new Nullpointerexception ("Flasche noch zu oder bereits geöffnet");
}
}
|