
상속과 컴포지션에 대해 알아보겠습니다. 상속은 부모클래스의 정의된 필드와 메서드를 자식클래스에서 물려 받는 것이고 컴포지션은 private 필드를 통하여 기존 클래스에 다른 클래스 인스턴스를 전달받는 것 입니다. 위의 설명 클래스들이 아래 소스에서와 같이 기존 클래스(Test)와 부모클래스(Test2), 다른 클래스(Test3)이 있습니다. public class Test extends Test2 { // 상속 private final Test3 test3; // 컴포지션 public Test(Test3 test3) { this.test3 = test3; } @Override protected void on() { super.on(); test3.on(); } public static void main(..