fork download
  1. interface U{
  2. void metod1();
  3. void metod2();
  4. void metod3();
  5. }
  6. class A{
  7. public static U makeU(){
  8. return new U() {
  9. public void metod1(){
  10. System.out.println("metod1");
  11. }
  12. public void metod2(){
  13. System.out.println("metod2");
  14. }
  15. public void metod3(){
  16. System.out.println("metod3");
  17. }
  18. };
  19. }
  20. }
  21. class B {
  22. public static U[] makeArU(int x) {
  23. System.out.println("Array U has length" + x);
  24. return new U[x];
  25. }
  26. public static U[] fillU(U[] u){
  27. for (int i = 0; i<u.length; i++) {
  28. u[i] = A.makeU();
  29. System.out.println("u object id "+i+" added to U array");
  30. }
  31. return u;
  32. }
  33. public static void callU(U[] u) {
  34. for (int i = 0; i < u.length; i++) {
  35. u[i].metod1();
  36. u[i].metod2();
  37. u[i].metod3();
  38. }
  39. }
  40. }
  41. public class Main {
  42. public static void main(String[] args) {
  43. B.callU(B.fillU(B.makeArU(5)));
  44. }
  45. }
  46.  
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Array U has length5
u object id 0 added to U array
u object id 1 added to U array
u object id 2 added to U array
u object id 3 added to U array
u object id 4 added to U array
metod1
metod2
metod3
metod1
metod2
metod3
metod1
metod2
metod3
metod1
metod2
metod3
metod1
metod2
metod3