You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
506 B

7 years ago
  1. //test if assigning from existing to new class is by reference or by value
  2. public class test{
  3. public static void main(String[] args){
  4. Example t1 = new Example(1);
  5. Example t2 = new Example(3);
  6. t2 = t1;
  7. t1.printT();
  8. t2.setT(2);
  9. t1.printT();
  10. t2.printT();
  11. }
  12. }
  13. class Example{
  14. int t;
  15. public Example(int t){
  16. this.t = t;
  17. }
  18. public void printT(){
  19. System.out.println(this.t);
  20. }
  21. public void setT(int t){
  22. this.t = t;
  23. }
  24. }