-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPrototype.java
45 lines (35 loc) · 981 Bytes
/
Prototype.java
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
42
43
44
45
import java.util.*;
interface Attack{
void setAttack(String str);
void printAttack();
}
class Naruto implements Attack, Cloneable {
private String attack;
public Naruto(){
}
public Naruto(String str){
this.attack = str;
}
@Override
public void setAttack(String str){
this.attack = str;
}
@Override
public void printAttack(){
System.out.println(attack);
}
public Naruto ShadowClone() throws CloneNotSupportedException {
return (Naruto) super.clone();
}
}
public class Main{
public static void main(String[] args) throws CloneNotSupportedException {
Naruto naruto = new Naruto();
ArrayList<String> attackList = new ArrayList<String>(Arrays.asList("RasenShuriken","Rasengan","Summoning Technique","Toad Oil Flame Bullet","Chibaku Tensei"));
for(int i=0;i<attackList.size();i++){
Naruto narutoClone = naruto.ShadowClone();
naruto.setAttack(attackList.get(i));
naruto.printAttack();
}
}
}