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. static class S {
  11. int val;
  12. }
  13.  
  14. public static void main (String[] args) throws Exception {
  15. S[] s = new S[4];
  16. for ( int i = 0; i < 4; ++i ) s[i] = new S();
  17. s[0].val = 10;
  18. s[1].val = 20;
  19. s[2].val = 30;
  20. s[3].val = 40;
  21. for ( int i = 0; i < 4; ++i ) System.out.printf( "s[%d]=%d\n", i, s[i].val );
  22.  
  23. System.out.println();
  24. S ns = s[1];
  25. s[1].val = 100;
  26. for ( int i = 0; i < 4; ++i ) System.out.printf( "s[%d]=%d\n", i, s[i].val );
  27. }
  28. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
s[0]=10
s[1]=20
s[2]=30
s[3]=40

s[0]=10
s[1]=100
s[2]=30
s[3]=40