Create and use objects (b)

1, to create and use objects

  ♦ create object syntax: name = new class name of the object class name ();

  ♦ Use "object. Object members" of access object members (including properties and methods)

 

2. Tips

  2.1 class access mechanism:

      ♣ access mechanism in a class: The class can directly access member variables of the class; exception: static method azimuthal non-static, the compiler does not pass

      ♣ access mechanism in different classes: first create the object you want to access the class members and then access the object defined in the class.

 

 3. Object life cycle

 

 

4. Memory resolve

 

    4.1, heap, the sole purpose of this memory area is stored object instance, almost all object instances are here to allocate memory. This is described in the Java Virtual Machine Specification is: all object instances and arrays to be allocated on the heap.

    4.2, commonly referred to as the stack, the stack is a virtual machine. VM stack for storing local variables and the like. The local variable table stored understood compile all the basic data types (boolean, byte, char, short, int, long, double) the length of the object reference (reference type, it is not equivalent to the object itself, the first object in the heap memory address). Method executed, automatic release

   4.3, method area, for storing information class virtual machine has been loaded, a constant, static variables, the real-time data such as the code compiler

5. Analytical memory object

 

 6. anonymous object

  1. We can not define the object's handle, and a method to directly call the object. Such objects are called anonymous objects, such as:

new Person().shout();

  2. Usage

    If an object requires only one method call, then you can use an anonymous object.

    We often anonymous object as an argument to a method call.

 

Guess you like

Origin www.cnblogs.com/lingtiaoti/p/12324384.html