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.
27 lines
506 B
27 lines
506 B
//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;
|
|
}
|
|
}
|