Java developers learning three

 

Filling in the gaps:

  A: class definition: basic embodiment; public static method return type name (parameter type parameter name, .......) {method body; return value return;}

Three kinds of method invocation; Note: void only for a single call; there must be a more important place! ! ! When defining the learning classes, defined when the member method and basic methods, members of the methods he does not need the static keyword, this should pay attention!

Familiar with the code! ! ! Here to explain when and when not to use the static keyword: When defining member methods do not, at this time because the method that is defined to be called by the object, rather than as before the main method defined together and by the main method in a class among called directly.

   Two: to write about multiple objects to create objects of use - the object passed by reference:

    1-per2 no open heap memory space -per2 = per1-> will per1 heap memory usage rights to per2; each stack memory space can modify the contents of heap memory.

    2-per2 also opened up a heap memory space -per2 = per1-> because per2 itself has pointed heap memory space, so how would like to point per1 corresponding space, you must disconnect the existing connection. Therefore, the existing heap space, stack space is not the point, to form a space garbage, waiting for Java garbage collection for recycling. Per2 at a time can also be modified in the heap memory data per1.

  III: Encapsulation: packaging and method of packaging properties

  Property package:. Private member variables Once private, can be accessed in any class, but! Beyond the outside of this class can not directly access the range, i.e., outside of this indirect access class setting and getting accessed indirectly using setter and getter methods. This can also be controlled grammar in the method - test code. setXxx setting data, assignment, no return value, but parameters; getXxx for pick up, there is a return value, return.

  IV: Constructors: main role is assigned to the class attributes. Note book p95 constructor.

   例;class Person{

      public Person(String name,int age){

        this.name = name; // this is the case with the member variables and parameters in order to distinguish

        this.age=age;

        //this.setName(name); this refers to an object and this

        //this.setAge(age);

        }

   Five; this keyword

    1. When the method of the class member variables and local variables of the same name when, in accordance with "the principle of proximity" preferentially use local variables, if the access class member variables among the present, we can use this, this. The local member variable to distinguish Relational variables

    2. Who is calling the method which object this.

   Six Relations. Local variables and member variables (parameters also when a local variable)

    1. Define the position is not the same

      Local variables: the interior of the method;

      Member variables: the external method, in which the direct write

    2. The scope is not the same

      Local variables: only available method among;

      Member variables: the entire class among

    3. The default values ​​are not the same

      Local variables: no default, to use the manual assignment;

      Member variable: there are defaults

   Seven .static keyword

      : If the property stated in the program, then the property known as global properties, (some also called static properties). After our static global variable to the value of the property needs to be changed, it is best to call directly by the class name.

    Call format class attributes: Attribute class name .static Example: Person.country = "B city";

    Java memory commonly used in four areas

      1 stack memory: save all object names (exact address is saved cited the heap memory space)

      2 heap memory: to save the contents of specific attributes of each object

      3 and global data: type of static storage properties

      Global code area 4: save all the methods defined 

    

Guess you like

Origin www.cnblogs.com/changanshisanzhao/p/11514701.html