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 生日广州男生祝福语简短