We can declare an interface within another interface or class. Such interfaces are called nested interfaces.
The following are the rules for managing nested interfaces.
The following is an example of nested interfaces.
Live Demonstration
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
The above is the detailed content of Nested interfaces in Java. For more information, please follow other related articles on the PHP Chinese website!