자바 상속1 2022-09-06 상속 상속 일반적으로 상속은 부모가 자식에게 재산을 물려주는 것을 뜻한다. 이와 유사하게 자바의 프로그래밍에서도 상속이 쓰이는데 부모클래스의 필드,메소드를 자식 클래스에게 물려주는 것이다. public class A{ String str="안녕하세요"; String str2="안녕못합니다"; void hello(){ System.out.println("부모 A의 인사"); } } //이를 class B가 물려 받을 경우, extend를 사용하면 된다. public class B extends A{ } public class Main { public static void main(String[] args) { B b = new B(); b.hello(); System.out.println(b.str2) } } .. 2022. 9. 6. 이전 1 다음