java02

garbage collection

  1. reference counting
  2. Reference reachability

create object

  1. Allocate object space and initialize object member variables to 0 or empty
  2. Execute display initialization of property value
  3. execute constructor
  4. Returns the address of the object to the associated variable

this keyword

  1. Where there is ambiguity in the program, this should be used to indicate the current object. In ordinary methods, this always points to the object that calls the method, and in the constructor, this always points to the object to be initialized.
  2. The overloaded constructor is called with the this keyword, avoiding the same initialization code, but it can only be used in the constructor, and must be in the first sentence of the constructor.
  3. this cannot be used in static methods.

static keyword

A member variable declared statically is a static member variable, also known as a class variable.

Static modified member variables and methods belong to the class, and ordinary variables and methods belong to the object.
Features:

  1. It is a public variable of the class, belongs to the class, is shared by all instances of the class, and is explicitly initialized when the class is loaded.

  2. For all objects of this class, there is only one static member variable. Shared by all objects of this class!!

  3. Generally use "class name. class attribute/method" to call. (Static members can also be accessed by object reference or class name (no instantiation required).)

  4. Non-static members cannot be directly accessed in static methods.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325162493&siteId=291194637