[java] 인터페이스의 필드는 어떻게 정의하고 사용하나요?
예를 들어, 다음과 같이 인터페이스 안에 상수를 정의할 수 있습니다:
public interface MyInterface {
int MAX_COUNT = 100;
String VERSION = "1.0";
}
인터페이스를 구현하는 클래스에서는 이러한 상수를 사용할 수 있습니다:
public class MyClass implements MyInterface {
public void displayConstants() {
System.out.println("Max count: " + MAX_COUNT);
System.out.println("Version: " + VERSION);
}
}
이렇게하면 인터페이스의 상수를 사용하는 방법을 보여줄 수 있습니다.