This link is inside construstor

I am looking at the Stanford Programming Methodology (CS106A) course in Java. In lecture 14, Professor Sahami talked about allocating memory in Java for functions and an object on the stack and heap.

He said that for any method called by the object, a stack and a list of arguments are allocated , and this link is allocated space on the stack. Through this directory, Java can reference the correct instance variables of an object.

stack - when method is called

but for constructor no, this link is saved along with a list of arguments, since the object is built.stack - when constructor is called

My questions: if the constructor does not have this refernece, then how can we use it inside the constructor for ex

public class foo {
private int i;
public foo(int i)
{this.i = i;// where this reference came from}
                 }
+5
2

this - Java, . .

this .

, i = i , ( ):

:

- , . , .

EDIT:

, , , .

,

class Point
{
  int x, y;
  Point(int x, int y) { this.x = x; this.y = y; }
  void move(int a, int b) { x = a; y = b; }
}
Point p = new Point(3,4);
p.move(1,2);

- : ( this )

class Point
{
  int x, y;
  static Point getPoint(int x, int y)
    { Point this = allocateMemory(Point); this.x = x; this.y = y; }
  static void move(Point this, int a, int b) { this.x = a; this.y = b; }
}
Point p = Point.getPoint(3,4);
Point.move(p, 1, 2);

, , .

+1

.
this , .

public class foo {
    private int i;

    public foo(int i) {
        this.i = i; // stores the argument i into the class level variable i
    }

    public foo2(int i) {
        i = i;    // stores the argument i into the argument i
    }
}
0

All Articles