fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. IShape3D[] s = new IShape3D[5];
  13. s[0] = new Cylinder();
  14. s[1] = new Cylinder();
  15. s[2] = new Square();
  16. s[3] = new Cylinder();
  17. s[4] = new Square();
  18.  
  19. for (int i = 0; i < 5; i++)
  20. {
  21. s[i].Draw();
  22. }
  23. }
  24. }
  25.  
  26. class Cylinder implements IShape3D
  27. {
  28. public void Draw()
  29. {
  30. System.out.println("cylinder");
  31. }
  32. }
  33.  
  34. class Square implements IShape3D
  35. {
  36. public void Draw()
  37. {
  38. System.out.println("square");
  39. }
  40. }
  41.  
  42. interface IShape3D
  43. {
  44. public void Draw();
  45. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
cylinder
cylinder
square
cylinder
square