
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Nested interface in Java
We can declare an interface in another interface or class. Such an interface is termed as a nested interface.
The following are the rules governing a nested interface.
- A nested interface declared within an interface must be public.
- A nested interface declared within a class can have any access modifier.
- A nested interface is by default static.
Following is an example of a nested interface.
Example
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(); } }
Output
Dogs can walk and run
- Related Articles
- Interface in Java
- Nested Classes in Java
- Deque interface in Java
- Externalizable Interface in Java
- Marker interface in Java
- Function interface in Java
- BinaryOperator Interface in Java
- IntUnaryOperator Interface in Java
- Serializable Interface in Java
- Why an interface cannot implement another interface in Java?
- Static Nested Classes in Java
- Interface enhancements in Java 8
- Set Interface in Java Programming
- SortedMap Interface in Java Programming
- ConcurrentMap Interface in java\n

Advertisements