880 likes | 1.07k Views
class Point { }. class Point { }. Point. class Point { int x, y; }. Point. x. y. class Point { int x, y; }. Point. x. y. class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } }. Point. x. y. Point. x. y.
E N D
class Point { } Point
class Point { int x, y; } Point x y
class Point { int x, y; } Point x y
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y This is a constructor, it looks just like a method (procedure, recipe), its purpose is just to describe the procedure for object initialization.
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x; this.y = y;
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x; this.y = y;
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x; this.y = y;
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point Sometime in the future, in another program:
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point Sometime in the future, in another program: Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point Here how it goes. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y First the blueprint is brought. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y We’ll use it to create an actual object. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y Someone will have to work on that. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y Here’s the action figure. This is our employee. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y He jumps right in. He works on the spaceship. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y this.x = x this.y = y The arguments he received are 3 and 5. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 x y this.x = x this.y = y The arguments he received are 3 and 5. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y this.x = x this.y = y The arguments he received are 3 and 5. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y this.x = x this.y = y So the employee reads the first line, and thinks… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y this.x = x this.y = y this.x (the x in this spaceship) must be set to… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y this.x = x this.y = y this.x (the x in this spaceship) must be set to… x Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y this.x = x this.y = y this.x (the x in this spaceship) must be set to… 3 Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y 3 this.x = x this.y = y so he takes the value in x in his left hand (3). Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point 3 5 x y 3 this.x = x this.y = y and places it in its right hand (the 3) Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x this.y = y and places it in this spaceship’s x slot… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x this.y = y and places it in this spaceship’s x slot… a slam dunk! Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x this.y = y then moves on to second instruction in his program Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x this.y = y it reads: this.y = y; Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x this.y = y Spiff says: `That ought to be easy!’ Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x 5 this.y = y With left hand he takes the y provided by the user… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 y Point 3 5 x y this.x = x 5 this.y = y …and moves it in his right hand… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y Point 3 5 x y this.x = x this.y = y For another slam dunk (I guess). Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y Point 3 5 x y this.x = x this.y = y Spiff’s job is done. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y He packs and leaves behind a full blown object. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y The object is completely initialized… Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y … and must be delivered to the customer. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y Spiff is happy. Spiff can go away. Point a = new Point(3, 5);
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y Spiff is off to help another customer. a
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y When a new order comes: Point b = new Point(-1, -1); a
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y x -1 -1 y When a new order comes: Point b = new Point(-1, -1); a
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y x -1 -1 y b It’s déjà vu already again… a
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x 3 5 y x -1 -1 y b a
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point x y
class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } Point x y Point Let’s ignore the variable(s) initialization details for now…