Learning java object-oriented third day ---

method

Definition method:

Modifier return type method name (parameter list) {

    Statements;

    return method returns a value;

}

修饰符:public private

this variable: implicit variables this, pointing to the current instance

Method parameters:

The method may include zero or any number of parameters. A method for variable parameters passed to the method of receiving a value. When calling the method, must be strictly in accordance with defined parameters one by one pass

variable parameter:

The variable parameters 类型...defined, the variable parameters corresponding to array type:

Parameter binding:

When the caller pass arguments to an example method, the value of the call will be passed by eleven parameters binding position.

 

Configuration method

The name of the constructor is the class name. Argument constructor is not limited, within the method, you can write any statements. And compared to the conventional method, the constructor does not return value (no void), call the constructor, must newoperator.

The default configuration method

class className(){

}

Note: If we customized a constructor that the compiler will no longer automatically create a default constructor:

 A plurality of constructors

A constructor can be configured to call other methods aimed at facilitating code reuse. Other constructor call syntax isthis(…)

The method of overload (overload)

In one class, a plurality of methods may be defined. If there are a number of ways, their function is similar, only the parameters are different, and that this group is made of the same name method name method.

Note: overloaded methods usually return type is the same.

The purpose method overloading is a similar function method using the same name, is easier to remember, easier to call up.

Guess you like

Origin www.cnblogs.com/maolin8023siyu/p/11572188.html