class Test Point 8 public static void mainString
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); creation of a point at < 0. 0 ; 0. 0 > Point 8 p 3 @1 p 2 null p 1 null x 0 y 0
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); creation of a point at < 2. 0 ; 3. 0 > Point 8 p 3 @1 p 2 null p 1 @2 x 0 y 0 Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); p 2. display(); P 2 p 3. display(); <x=2; y=3> has not been initialized and is still null, the display method can not be applied. <x=0; y=0> Point 8 p 3 @1 p 2 null p 1 @2 x 0 y 0 Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; Point 8 p 3 @1 p 2 @2 p 1 @2 x 0 y 0 Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; p 3. move(2, 3); Point 8 p 3 @1 p 2 @2 p 1 @2 x 2 y 3 Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; p 3. move(2, 3); p 1. display(); p 2. display(); p 3. display(); System. out. println("p 1 == p 2 : " + (p 1==p 2)); System. out. println("p 1 == p 3 : " + (p 1==p 3)); System. out. println("p 3 == p 2 : " + (p 3==p 2)); <x=2; y=3> p 1 == p 2 : true p 1 == p 3 : false p 3 == p 2 : false Point 8 p 3 @1 p 2 @2 p 1 @2 x 2 y 3 Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; p 3. move(2, 3); p 1. display(); p 2. display(); p 3. display(); System. out. println("p 1 == p 2 : " + (p 1==p 2)); System. out. println("p 1 == p 3 : " + (p 1==p 3)); System. out. println("p 3 == p 2 : " + (p 3==p 2)); p 3 = p 1; Point 8 p 3 @1 p 2 @2 p 1 @2 x 2 y 3 This object is not referenced anymore and will be collected by the garbage collector to free the memory space it is using. Point 8 x 2 y 3
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; p 3. move(2, 3); p 1. display(); p 2. display(); p 3. display(); System. out. println("p 1 == p 2 : " + (p 1==p 2)); System. out. println("p 1 == p 3 : " + (p 1==p 3)); System. out. println("p 3 == p 2 : " + (p 3==p 2)); p 3 = p 1; p 3. move(2, 3); p 3 @1 p 2 @2 p 1 @2 Point 8 x 4 y 6
class Test. Point 8 { public static void main(String[] arg) { Point 8 p 1; Point 8 p 2; Point 8 p 3 = new Point 8(); p 1 = new Point 8(2, 3); p 1. display(); // p 2. display(); p 3. display(); p 2 = p 1; p 3. move(2, 3); p 1. display(); p 2. display(); p 3. display(); System. out. println("p 1 == p 2 : " + (p 1==p 2)); System. out. println("p 1 == p 3 : " + (p 1==p 3)); System. out. println("p 3 == p 2 : " + (p 3==p 2)); p 3 = p 1; p 3. move(2, 3); p 1. display(); p 2. display(); p 3. display(); } } p 3 @1 p 2 @2 p 1 @2 <x=4; y=6> Point 8 x 4 y 6
- Slides: 9