Java: class5 class overloads, final, static

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43336822/article/details/95598780

A, overloaded function (same class):
Condition: the same function name 1
2 lists different parameters (number, type)
two, the this (): call the constructor in the current class
Note: 1.this ( ) must be in the first row of the currently valid code constructor
2. the constructor may not call each other
can not call the constructor 3. a plurality constructor (the first collision)
two, static
1. static variables and instance variables the difference:
1. instance variables and objects related to an object (a new) corresponds to a member variable this-> points to the current object
static variables and class, but not with the object, there is no current static variables of this implicit reference
2. storage location: instance variables in the heap (new new); static variables (area method)
3. Called: instance variables: reference variable p.name.
static variable: class name Arrays.copyOf ().

// class defined in a static int num; constructor num ++, public int getnum () {return num;} can count the number of objects the current
time that is necessary to define a static variable, otherwise every num will re-create the object 0 +1 again

2. Use static modification of the method (static method) does not offer this reference, that is not the object into the implicit transfer method.
You can not refer to static methods non-static method, because the incoming non-static methods must have an object, and static methods and can not be transferred; rather than a static method can call the static method of providing this references but it does not use it.
Three, Final
1.final: After often with the name of a static, constant must be in all caps

Guess you like

Origin blog.csdn.net/qq_43336822/article/details/95598780