Nested Interfaces in Java


Create a Java program to demonstrate the use of nested interfaces

  • The Outer interface contains a method outerMethod() and a nested interface Inner containing a method innerMethod().
  • The MyClass class implements the Inner interface and provides an implementation for the innerMethod() method.
  • In the Main class, we create an instance of MyClass and call the innerMethod(), which prints "Inner method implementation" to the console.

Source Code

interface Outer
{
	void outerMethod();
 
	interface Inner
	{
		void innerMethod();
	}
}
 
class MyClass implements Outer.Inner
{
	@Override
	public void innerMethod()
	{
		System.out.println("Inner method implementation");
	}
}
 
public class Main
{
	public static void main(String[] args)
	{
		MyClass myClass = new MyClass();
		myClass.innerMethod();
	}
}

Output

Inner method implementation

Example Programs