자바 HAS-A 관계 예시
class Gun { int bullet; public Gun(int bnum) { bullet = bnum; } public void shoot(){ System.out.println("BBANG"); bullet--; } } class Police extends Gun { int handcuffs; // 소유한 수갑의 수 public Police(int bnum, int bcuff) { super(bnum); handcuffs = bcuff; } public void putHandcuff(){ System.out.println("SNAP"); handcuffs--; } } public class InheritanceEx05 { public static void main(String[] args) { ..
카테고리 없음
2024. 4. 11. 18:19