OnJava8-Examples/operators/Assignment.java

31 lines
718 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// operators/Assignment.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
// Assignment with objects is a bit tricky.
import static com.mindviewinc.util.Print.*;
class Tank {
int level;
}
public class Assignment {
public static void main(String[] args) {
Tank t1 = new Tank();
Tank t2 = new Tank();
t1.level = 9;
t2.level = 47;
print("1: t1.level: " + t1.level +
", t2.level: " + t2.level);
t1 = t2;
print("2: t1.level: " + t1.level +
", t2.level: " + t2.level);
t1.level = 27;
print("3: t1.level: " + t1.level +
", t2.level: " + t2.level);
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
1: t1.level: 9, t2.level: 47
2: t1.level: 47, t2.level: 47
3: t1.level: 27, t2.level: 27
2015-09-07 11:44:36 -06:00
*/