Java中的嵌套接口
我们可以在另一个接口或类中声明一个接口。这样的接口被称为嵌套接口。
以下是管理嵌套接口的规则。
在接口内声明的嵌套接口必须是公共的。
在类中声明的嵌套接口可以具有任何访问修饰符。
嵌套接口默认为静态。
以下是嵌套接口的示例。
示例
class Animal {
interface Activity {
void move();
}
}
class Dog implements Animal.Activity {
public void move() {
System.out.println("Dogs can walk and run");
}
}
public class Tester {
public static void main(String args[]) {
Dog dog = new Dog();
dog.move();
}
}输出结果
Dogs can walk and run
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短