Skip to content

Instantly share code, notes, and snippets.

@theArjun
Created January 14, 2019 15:31
Show Gist options
  • Select an option

  • Save theArjun/389fed91d9ea48352aed91a62ed692b1 to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/389fed91d9ea48352aed91a62ed692b1 to your computer and use it in GitHub Desktop.
Nested Interface Implementation
class Animal{
// Creating the interface inside class; nested interface.
interface Activity{
public default void move(){
System.out.println("Animal is moving.");
}
}
}
// To get access to Nested Interface : we write OuterClassName.NestedClasName
class Dog implements Animal.Activity{
public void move(){
System.out.println("Dog is moving.");
}
}
class NestedInterfaceDemo{
public static void main(String[] args){
Dog dogObject = new Dog();
dogObject.move();
// This is how, we refer to subclass object from nested interface referrer variable.
Animal.Activity nestedReferrerOne = new Dog();
nestedReferrerOne.move();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment