Review Notes Java 3 - Method operators

Standard review your notes are not suitable for zero-based

Assignment Operators

Variable name = value / expression;

Note that the assignment operator is calculated in accordance with right to left;

image-20191110102255862

note:
1. In use of assignments, type type must ensure that the range of not less than the right side of the left produced
2. The results of two types of different types of data are added, obtained for the larger one

Arithmetic Operators

image-20191110114251076

"+" Sign only as summation, it may also be used string concatenation
note
1. The addition performed from left to right, if you encounter a string object begins, subsequent splicing operation have become a string
2. If the division sign both sides are divided by said integer, retaining only the integer part of the result, when the required fractional part, wherein the numerator and denominator becomes a floating point arithmetic can then
3 + / -., Then the symbol preceding the first computing assigned, a first copy after recalculation

Category Operator

1. unary operators, operators need only one target data example: ++ - -

2. A binary operator, two operators require certain data, such as: addition, subtraction

3. ternary operator, two operators require certain data, boolean flag = 10> 20 true:? False;

Note: switch statement to determine the conditions can not be a floating point number

method

grammar:

权限修饰符 静态修饰符  返回值类型(参数列表){
  方法体
}

//其中仅有返回值类型和方法名称为必须的

Method overloading

When the same method name list of a plurality of process parameters, but not the same method overload is generated

Different types of parameters, number of different parameters, can reload

Return type, with the permission modifier may be arbitrary

Use when need to reload, when the same functional purpose of the two methods, but the method of parameter types can be processed simultaneously without the use of heavy-duty, the method may be simplified

And pass a reference value transfer

1. If the actual parameter data type basis, the value is passed to process the operation body modification parameters are local variables, it does not affect any external data

2. If the actual parameter when the object is passed by reference, if the method body code is the object of the operation itself, the operation is the same piece of memory

variable parameter

When the number of parameters in doubt, use a variable parameter

grammar:

void funcName(int... args){
  
}

// 调用时可以传递0-无穷个参数
// 需要注意
    1.当参数列表中存在其他参数时,必须位于可变参数的前面
    2.一个方法仅允许存在一个可变参数
    3.在方法重载时,优先访问不带可变参数的方法  
  4.本质上可变参数就是一个数组
void funcName(String name,int... args){
}

Guess you like

Origin www.cnblogs.com/yangyuanhu/p/11901694.html