: 부모 클래스에 만들어진 필드, 메소드를 자식 클래스가 물려받음
상속을 통해 간결한 자식 클래스 작성
└ 동일한 특성 재정의 필요 ❌ → 자식 클래스 간결
클래스의 간결화
: 멤버의 중복 작성 불필요
클래스의 관리 용이
: 클래스들의 계층적 분류
소프트웨어의 생산성 향상
: 재사용과 확장 용이
클래스의 다중 상속 지원 ❌ (클래스를 여러 개 상속 불가)
상속 횟수는 무제한이다.
상속의 최상위 조상 클래스는 java.lang.Object 클래스이다.
└ 컴파일러에 의해 자동으로 상속이 이루어진다.

public class Person {
...
}
public class Student extends Person { // Person 을 상속받는 클래스 Student 선언
...
}
public class StudentWorker extends Student { // Student 를 상속받는 StudentWorker 선언
...
}
부모 클래스 → 슈퍼 클래스(super class) 라고도 함
자식 클래스 → 서브 클래스(sub class) 라고도 함
extends 키워드 사용
└ 슈퍼 클래스의 확장 개념
Ex 1
public class ColorPointEx {
public static void main(String[] args) {
Point p = new Point();
p.set(1,2);
p.showPoint();
ColorPoint cp = new ColorPoint();
cp.set(3,4);
cp.setColor("red");
cp.showColorPoint();
}
}
class Point{
private int x, y;
public void set(int x, int y){
this.x = x;
this.y = y;
}
public void showPoint(){
System.out.println("("+x+","+y+")");
}
}
class ColorPoint extends Point {
private String color;
public void setColor(String color){
this.color = color;
}
public void showColorPoint(){
System.out.print(color);
showPoint();
}
}