Advertisement
morganm

Untitled

Jan 4th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. 18:58 [java_a] air> more OverLoad.java
  2. public class OverLoad {
  3. static private Base[] arr = new Base[2];
  4. public static void main(String[] args) {
  5. arr[0] = new A();
  6. arr[1] = new B();
  7. Manager mgr = new Manager();
  8. for(int i=0; i < arr.length; i++) {
  9. mgr.test(arr[i]);
  10. }
  11. System.out.println("finished");
  12. }
  13.  
  14. static class Manager {
  15. public void test(A arg) {
  16. System.out.println("A: "+arg);
  17. }
  18. public void test(B arg) {
  19. System.out.println("B: "+arg);
  20. }
  21. public void test(Base arg) {
  22. System.out.println("Base: "+arg);
  23. }
  24. }
  25.  
  26. static interface Base {}
  27. static class A implements Base {}
  28. static class B implements Base {}
  29. }
  30. 18:59 [java_a] air> java OverLoad
  31. Base: OverLoad$A@33dff3a2
  32. Base: OverLoad$B@33f42b49
  33. finished
  34. 18:59 [java_a] air>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement