본문 바로가기
Java 배우기

Summary of Inheritance 상속 요약

by 노화방지 Anti-aging Hairstyle 2016. 1. 5.
반응형


클래스 Object를 제외하고, 1개의 클래스는 정확히 1개의 직접 수퍼클래스를 갖고 있습니다.
클래스는 모든 그 수퍼클래스들로부터 직접 또는 간접적으로 필드들과 메소드들을 상속받습니다.
서브클래스는 상속받는 메소드를 override 할 수 있으며, 또는 상속받는 필드들이나 메소드들을 감출 수 있습니다(필드 감추기는 나쁜 프로그래밍 습관입니다).

Except for the Object class, a class has exactly one direct superclass. A class inherits fields and methods from all its superclasses, whether direct or indirect. A subclass can override methods that it inherits, or it can hide fields or methods that it inherits. (Note that hiding fields is generally bad programming practice.)

섹션 Overriding and Hiding Methods에 있는 표는 superclass의 메소드와 같은 시그니처를 가진 메소드를 선언하는 것의 효과를 보여주고 있습니다.

클래스 Object 는 클래스 계층의 최상에 있습니다.
모든 클래스들은 이 클래스의 descendants이며 이 클래스로부터 메소드들을 상속받습니다.
Object에서 상속받는 유용한 메소드로는 toString()equals()clone(), getClass()가 있습니다.

The table in Overriding and Hiding Methods section shows the effect of declaring a method with the same signature as a method in the superclass.

The Object class is the top of the class hierarchy. All classes are descendants from this class and inherit methods from it. Useful methods inherited from Object include toString()equals()clone(), and getClass().


클래스 선언에 키워드 final를 사용하면 서브클래스화 되는 것을 방지할 수 있습니다.
비슷하게, 메소드를 final method로 선언함으로써 서브클래스에 의하여 그 메소드가 오버라이딩 되는 것을 방지할 수 있습니다.

abstract class는 subclass화만 될 수 있으며; 인스턴스화는 될 수 없습니다.
abstract class는 abstract methods를 포함할 수 있는데—이 메소드는 선언 만 되고 구현되지 않은 메소드 입니다.
그러면 서브클래스가 추상 메소드에 대하여 구현을 제공합니다.
You can prevent a class from being subclassed by using the final keyword in the class's declaration. Similarly, you can prevent a method from being overridden by subclasses by declaring it as a final method.

An abstract class can only be subclassed; it cannot be instantiated. An abstract class can contain abstract methods—methods that are declared but not implemented. Subclasses then provide the implementations for the abstract methods.



반응형

댓글