Java Medium this The keyword always points to the object that called the method . according to this There are different positions ,this As a default reference to an object, there are two functions :

1. The constructor references the object that the constructor is initializing .

2. Reference the object calling the method in the method .

this The most important function of keyword is to let a method in the class , Access another method or instance variable in the class . Suppose you define a Student class , This student The object's method of recording results (scores()) The name property needs to be called , So how do you do that ? Please see the following example :

public class Student {
    private int scores;
    private String names;
    public void name(String name) {
        this.names = name;
    }
    public void score(int score) {
        this.scores = score;
        System.out.println(this.names +" The result is :"+this.scores);
    }
}

In the refactoring of methods ,this You can also call construction methods , It should be noted that :

this() It can only be written in the constructor of this class , It can't be used in any other non construction method ;
this() It can only be written in the first sentence of the construction method .
this() You can put formal parameters in brackets , Call other construction methods of this class .
this.*** perhaps this.***() Representing each object itself this quote

Object's this More related articles cited

  1. Reference passing between objects And .NET Deep and shallow copies in

    1. scene First , The scene is like this . There is one Person class , One of the types in the class is Car Properties of . Used to express , People drive cars . Car There are some properties in the class that describe things like carpool . This is the basic scenario .   2. Shallow copy Person ...

  2. java object Integer Cannot pass... By reference

    java object Integer Cannot pass... By reference /** * The value of the <code>Integer</code>. * * @serial */ private ...

  3. SQL Server Look at the reference relationships between objects

    Preparation : use studioA;           go create table T(X int,Y int); insert into T(X,Y) values(1,1),(2,2);  ...

  4. OC Reference count of object elements in Related concepts of auto release pool

    OC How to deal with the reference counting problem of object elements in array objects , At the same time, this paper introduces the related concepts of automatic release pool One . How does an array object deal with the reference counting of object elements [objc]  view plaincopy 1. //   2. / ...

  5. [ translate ] Write high performance .NET Code -- Chapter two GC -- Reduce the distribution rate , The most important rule , Shorten the life cycle of objects , Reduce the depth of the object hierarchy , Reduce references between objects , Avoid pinning objects (Pinning)

    Reduce the distribution rate There's hardly any explanation for this , Reduced memory usage , Naturally there will be less GC The pressure of recovery , At the same time, memory fragmentation and CPU Usage of . You can do this in a number of ways , But it can conflict with other designs . You need to be careful when designing objects ...

  6. It's very easy to understand ‘ class &#39; And &#39; object ’ between attribute Reference relationship , and 《Python A preliminary understanding of references and class properties in 》 Journal entry

    keyword : name , The name space , quote , The pointer , Pointer type pointer ( The pointer to the pointer ) The summary of my understanding after reading : 1. We know ,python The assignment of variables in , A variable is actually a name name, An assignment is to assign name Reference to a ...

  7. python Of del Function delete object or delete reference

    1. First of all python Object reference of 1)Python There is no value call in , Everything passed is an object reference , It can also be considered as an address call . namely Python Programmers are not allowed to choose to pass values or references .Python Parameter passing uses “ Pass it on ...

  8. java A strong reference to an object , Soft citation , Weak quotation and virtual quotation

    1. Strong citation Most of the references we used before are actually strong references , This is the most commonly used quotation . If an object has a strong reference , It's similar to the necessities , The garbage collector will never recycle it . When memory is empty Deficiency of space ,Java The virtual machine would rather throw Out ...

  9. C++ Common references to objects in

    Pass the object name directly When you use an object name as a function parameter , A new object is created when the function is called , It's a copy of the formal parameter object . ================ Here's an example of passing object names directly 1.1================= ...

Random recommendation

  1. js Special string filtering for text boxes

    HTML in onkeyup="stripscript(this)"; function stripscript(obj) { var s = $(obj).val(); var ...

  2. java mongoDB Secondary array nested query

    scene : There are multiple member documents under the member collection , There are multiple order documents under the member document , Orders buy multiple product documents member->orders>orderItems requirement : Through members id And commodities id Verify whether the member has purchased the product ...

  3. unix&amp;linux University Course Catalog

    The first 1 Chapter unix brief introduction The first 2 What is linux? What is? unix The first 3 Chapter unix Connect The first 4 Chapter one is in use unix The first 5 Chapter gui: Graphical user interface The first 6 Chapter unix The work environment The first 7 Chapter unix Keyboard use The first 8 The chapter can be used immediately ...

  4. WebService Basic concepts and principles

    One .Web Service Basic concepts WebService Is a cross programming language and cross operating system platform remote call technology .Web Service Also called XML Web Service WebService It's one that can receive from I ...

  5. Elaborate JavaScript Some things about single thread

    label : JavaScript Single thread The starting address : Yard rural network < Elaborate JavaScript Some things about single thread > Recently, I was asked by my classmates JavaScript Some things about single thread , I can't answer . ok , Feel your own Ja ...

  6. nyoj 1100 WAJUEJI which home strong!

    WAJUEJI which home strong! The time limit :1000 ms  |  Memory limit :65535 KB difficulty :2   describe In a gully , The sister and brother were admitted to university at the same time . But because of the family's financial difficulties , So it's not ...

  7. 【2-24】for A nested loop , Jump statements , Exception statements , Exhaustive method 、 Iterative method

    For Loop nesting and if Nesting is similar , Is in for In the middle again set for, Its structure is as follows : For(;;) { For(;;){} } The classic question type is printing stars : Console.Write(" Please enter an odd number :" ...

  8. Lua In function calls and coroutines , Stack changes

    Lua In function calls and coroutines , Stack changes 1. lua_call / lua_pcall   For these two functions , It has no effect on the bottom of the stack -- When called , Parameters are removed from the stack , When the function returns to On the way back , The return value will come from the function ...

  9. Genymotion Download and install

    quote https://blog.csdn.net/yht2004123/article/details/80146989 One . register \ Sign in open Genymotion Official website ,https://www.genym ...

  10. MySQL Common commands ( database , Table related commands )

    Database related commands Show database list mysql> SHOW  DATABASES; Create database mysql> CREATE  DATABASE  Library name ; as follows , Create a file called crashcours ...