SHOW:
|
|
- or go back to the newest paste.
1 | import java.util.*; | |
2 | - | public static void main (String... args){ |
2 | + | import java.lang.*; |
3 | - | MyInterface[] = {new ImplOne, new ImplTwo}; |
3 | + | import java.io.*; |
4 | ||
5 | - | for (MyInterface i : iList) { |
5 | + | |
6 | - | System.out.println(i.getString()); |
6 | + | public static void main (String[] args){ |
7 | - | } |
7 | + | MyInterface[] iList = {new ImplOne(), new ImplTwo()}; |
8 | - | } |
8 | + | |
9 | for (MyInterface i : iList) { | |
10 | System.out.println(i.getString()); | |
11 | } | |
12 | - | public String getString(); |
12 | + | } |
13 | } | |
14 | ||
15 | interface MyInterface{ | |
16 | - | @Override |
16 | + | public String getString(); |
17 | - | public String getString(){ return "Who am I?"; } |
17 | + | |
18 | ||
19 | class ImplOne implements MyInterface{ | |
20 | @Override | |
21 | - | @Override |
21 | + | public String getString(){ return "Who am I?"; } |
22 | - | public String getString(){ return "I am YOU."; } |
22 | + | |
23 | ||
24 | class ImplTwo implements MyInterface{ | |
25 | @Override | |
26 | public String getString(){ return "I am YOU."; } | |
27 | } |