231220 JAVA avengers 패키지

2023. 12. 20. 19:382023.11.21-2024.05.31

 

package avengers;

 

public class Avengers {

 

public static void main(String[] args) {

// 인스턴스 생성

 

Ironman ironman = new Ironman();

Spiderman spiderman = new Spiderman();

Flerken flerken = new Flerken();

 

flerken.attack();

ironman.attack();

spiderman.attack();

 

ironman.makeSuit(5);

 

flerken.fly();

ironman.fly();

spiderman.fly();

 

flerken.defence();

ironman.defence();

spiderman.defence();

 

 

}

 

}

 

package avengers;

 

public abstract class Hero {

String name;

int age;

int hp;

 

}

 

 

package avengers;

 

public interface Fly {

public void fly();

 

}

 

package avengers;

 

public interface Attack {

public abstract void attack();

 

void defence();

 

}

 

package avengers;

 

public interface Javis {

public abstract void makeSuit(int count);

 

}

 

package avengers;

 

public class Ironman extends Hero implements Attack, Fly, Javis {

 

@Override

public void fly() {

System.out.println("날아라");

 

}

 

@Override

public void attack() {

System.out.println("레이저 공격!");

 

}

 

@Override

public void defence() {

System.out.println("방어 방어!");

 

}

 

@Override

public void makeSuit(int count) {

System.out.println(count + "개 만들어줘.");

 

}

 

}

 

 

package avengers;

 

public class Spiderman extends Hero implements Attack, Fly {

 

@Override

public void fly() {

System.out.println("거미줄 피슝!");

 

}

 

@Override

public void attack() {

System.out.println("거미줄 공격!");

 

}

 

@Override

public void defence() {

System.out.println("거미줄 방어!");

 

}

 

}

 

package avengers;

 

public class Flerken extends Hero implements Attack,Fly {

 

@Override

public void attack() {

System.out.println("덩치 공격!");

 

}

 

@Override

public void defence() {

System.out.println("부수기 방어!");

 

}

 

@Override

public void fly() {

System.out.println("하늘에서 떨어지는 덩치!");

 

}

 

 

 

}

'2023.11.21-2024.05.31' 카테고리의 다른 글

231220 JAVA IsAHasA  (1) 2023.12.21
231220 JAVA memory(메모리 구조)  (0) 2023.12.20
231220 JAVA zoo 패키지(다형성)  (0) 2023.12.20
231220 JAVA Inter02(인터페이스)  (0) 2023.12.20
231220 JAVA Inter01(인터페이스)  (0) 2023.12.20