Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- class InterfaceExample{
- public static void main (String[] args){
- MyInterface[] iList = {new ImplOne(), new ImplTwo()};
- for (MyInterface i : iList) {
- System.out.println(i.getString());
- }
- }
- }
- interface MyInterface{
- public String getString();
- }
- class ImplOne implements MyInterface{
- @Override
- public String getString(){ return "Who am I?"; }
- }
- class ImplTwo implements MyInterface{
- @Override
- public String getString(){ return "I am YOU."; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement