Advertisement
Guest User

interface example

a guest
Feb 24th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class InterfaceExample{
  6.         public static void main (String[] args){
  7.                 MyInterface[] iList = {new ImplOne(), new ImplTwo()};
  8.  
  9.                 for (MyInterface i : iList) {
  10.                         System.out.println(i.getString());
  11.                 }
  12.         }
  13. }
  14.  
  15. interface MyInterface{
  16.         public String getString();
  17. }
  18.  
  19. class ImplOne implements MyInterface{
  20.         @Override
  21.         public String getString(){ return "Who am I?"; }
  22. }
  23.  
  24. class ImplTwo implements MyInterface{
  25.         @Override
  26.         public String getString(){ return "I am YOU."; }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement