본문 바로가기
Java 배우기

Defining an Interface 인터페이스 정의하기

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

인터페이스 정의 하기       Defining an Interface


interface 선언은 modifiers, 키워드 interface, interface 이름, 쉼표로 분리된 부모 interface 목록(if any), interface 몸체로 구성됩니다.
예를 들면:
An interface declaration consists of modifiers, the keyword interface, the interface name, a comma-separated list of parent interfaces (if any), and the interface body. For example:

public interface GroupedInterface extends Interface1, Interface2, Interface3 {

    // 상수 선언  constant declarations
    
    // base of natural logarithms
    double E = 2.718282;
 
    // method signatures
    void doSomething (int i, double x);
    int doSomethingElse(String s);
} 

public 접근 지정자는 인터페이스를 모든 패키지의 모든 클래스가 사용할 수 있음을 나타냅니다.
인터페이스를 
public으로 지정하지 않으면, 인터페이스와 동일한 패키지에 정의된 클래스만이 인터페이스에 접근할 수 있습니다.

인터페이스는 클래스의 하위클래스로, 다른 인터페이스를 확장하거나 다른 클래스를 확장할 수 있습니다.
단, 클래스가 다른 클래스를 1개만 확장할 수 있는 반면, 인터페이스는 여러 개의 인터페이스를 확장할 수 있습니다.
인터페이스 선언에는 쉼표로 구분된 확장된 모든 인터페이스의 목록이 포함되어 있습니다.
The 
public access specifier indicates that the interface can be used by any class in any package. If you do not specify that the interface is public, then your interface is accessible only to classes defined in the same package as the interface.

An interface can extend other interfaces, just as a class subclass or extend another class. However, whereas a class can extend only one other class, an interface can extend any number of interfaces. The interface declaration includes a comma-separated list of all the interfaces that it extends.

인터페이스 몸체 The Interface Body

interface 몸체에는 추상 메소드기본 메소드, static 메소드가 포함될 수 있습니다.
인터페이스 안의 추상 메소드의 뒤에는 semicolon이 오지만, braces는 없습니다(추상 메소드에는 구현이 포함되지 않음).
기본 메소드들은 default modifier로 정의되며, static 메소드들은 키워드 static으로 정의됩니다.
인터페이스 안의 모든 추상, 기본, static 메소드들은 묵시적으로  public이기 때문에 public modifier를 생략해도 됩니다.

추가로, interface에는 constant 선언이 포함될 수 있습니다.
인터페이스에 정의된 모든 constant 값은  묵시적으로 publicstatic, final입니다.
다시 한 번, 이들 modifiers.를 생략해도 됩니다.

The interface body can contain abstract methodsdefault methods, and static methods. An abstract method within an interface is followed by a semicolon, but no braces (an abstract method does not contain an implementation). Default methods are defined with the default modifier, and static methods with the static keyword. All abstract, default, and static methods in an interface are implicitly public, so you can omit the public modifier.

In addition, an interface can contain constant declarations. All constant values defined in an interface are implicitly publicstatic, and final. Once again, you can omit these modifiers.


반응형

댓글