//test if assigning from existing to new class is by reference or by value public class test{ public static void main(String[] args){ Example t1 = new Example(1); Example t2 = new Example(3); t2 = t1; t1.printT(); t2.setT(2); t1.printT(); t2.printT(); } } class Example{ int t; public Example(int t){ this.t = t; } public void printT(){ System.out.println(this.t); } public void setT(int t){ this.t = t; } }