단일 수준 상속 - 클래스는 단일 클래스의 속성을 상속합니다. 예를 들어 클래스 B는 클래스 A를 상속합니다.
예
class Shape {
public void display() {
System.out.println("Inside display");
}
}
class Rectangle extends Shape {
public void area() {
System.out.println("Inside area");
}
}
public class Tester {
public static void main(String[] arguments) {
Rectangle rect = new Rectangle();
rect.display();
rect.area();
}
} 출력
Inside display Inside area
여기서 Rectangle 클래스는 Shape 클래스를 상속받으며 그림과 같이 display()와 area()의 두 가지 메소드를 실행할 수 있습니다.