2011년8월10일_JAVA_상속과 인터페이스, 슈퍼클래스생성자호출문super, 레퍼클래스
JAVA에 대한 시간투자는 아깝다...
참조(Reference) |
● MyWorld.java
1: package kr.ac.busanit.MyWorld;
2:
3: class Warrior {
4: String name;
5: String weapon;
6:
7: Warrior () {
8: this.weapon = "맨손";
9: }
10:
11: Warrior (String name) {
12: this.name = name;
13: this.weapon = "맨손";
14: }
15:
16: void attack() {
17: System.out.println(this.name + "는 " + this.weapon + "으로 공격하다.");
18: }
19: }
20:
21: class DarkWarrior extends Warrior {
22:
23: DarkWarrior(String name) {
24: super(name);
25: this.name = "어둠의 " + name;
26: this.weapon = "복마화령검";
27: }
28:
29: DarkWarrior(Warrior warrior) {
30: this.name = "어둠의 " + warrior.name;
31: this.weapon = "복마화령검";
32: }
33: }
34:
35: public class MyWorld {
36:
37: /**
38: * @param args
39: */
40: public static void main(String[] args) {
41: // TODO Auto-generated method stub
42: Warrior chulsu = new Warrior();
43: chulsu.name = "철수";
44: chulsu.attack();
45:
46: DarkWarrior darkChulsu = new DarkWarrior(chulsu);
47: darkChulsu.attack();
48: }
49:
50: }
<실행결과>