Interface with a Nested Class and a Constant Field - Java Object Oriented Design

Java examples for Object Oriented Design:interface

Description

Interface with a Nested Class and a Constant Field

Demo Code

interface Walkable {
  // A nested class
  class Dog implements Walkable {
    private Dog() {
      // Do not allow outside to create its object
    }//  w w  w .ja  v a  2 s  .c o  m

    public void walk() {
      System.out.println("Nothing serious to run...");
    }
  }

  Walkable Default = new Dog();
  
  // An abstract method
  void walk();
}


public class Main {
  public static void main(String[] args) {
    my(Walkable.Default);    
  }

  public static void my(Walkable a) {
    a.walk();
  }
}

Result


Related Tutorials