不能在接口內部放置任何代碼,但是可以放置嵌套類(內部類),並且是自動public
和static
的。
如:
public interface ClassInInterface {
void howdy();
/**
* 接口中的內部類,可以實現其外圍接口
*/
class Test implements ClassInInterface {
public void howdy() {
System.out.println("Howdy!");
}
public static void main(String[] args) {
new Test().howdy();
}
}
}