Examples of smaller Java programs that do various interesting things.

ObjectVarsAsParameters.java 961B

123456789101112131415161718192021222324252627282930313233343536
  1. import java.awt.Rectangle;
  2. public class ObjectVarsAsParameters
  3. { public static void main(String[] args)
  4. { go();
  5. }
  6. public static void go()
  7. { Rectangle r1 = new Rectangle(0,0,5,5);
  8. System.out.println("In method go. r1 " + r1 + "\n");
  9. // could have been
  10. //System.out.prinltn("r1" + r1.toString());
  11. r1.setSize(10, 15);
  12. System.out.println("In method go. r1 " + r1 + "\n");
  13. alterPointee(r1);
  14. System.out.println("In method go. r1 " + r1 + "\n");
  15. alterPointer(r1);
  16. System.out.println("In method go. r1 " + r1 + "\n");
  17. }
  18. public static void alterPointee(Rectangle r)
  19. { System.out.println("In method alterPointee. r " + r + "\n");
  20. r.setSize(20, 30);
  21. System.out.println("In method alterPointee. r " + r + "\n");
  22. }
  23. public static void alterPointer(Rectangle r)
  24. { System.out.println("In method alterPointer. r " + r + "\n");
  25. r = new Rectangle(5, 10, 30, 35);
  26. System.out.println("In method alterPointer. r " + r + "\n");
  27. }
  28. }