2012-02-16 3 views
1

필드가있는 인터페이스가 있다고 가정 해 봅시다. String type = "interface".
구현 클래스에는 field - String type = "class"가 있습니다.
더 이상 해당 클래스를 통해 인터페이스의 필드에 액세스 할 수 있습니까?인터페이스의 재정의 된 변수

답변

2

네 .. 기본적으로 .. 상수, 공공 정적 최종 또는 다른 단어에있는 변수를 인터페이스 때문에

당신은 사용하여 정적 방식으로 액세스 할 수 있습니다

IYourInterfaceName.type 
+0

+1이 작동하는 이유에 대한 설명입니다. –

2
public interface Firstone { 
String type="interface"; 
} 
public class Abc implements Firstone { 

/** 
* @param args 
*/ 
String type="class"; 
void check(){ 

    System.out.println("my class\t"+type); 
    System.out.println("my interface\t"+Firstone.type); 
} 

public static void main(String[] args) { 

    Abc a=new Abc(); 
    a.check(); 
} 

}

관련 문제