Method Signatures
| English | Chinese | Pinyin |
|---|---|---|
| method | 方法 | fāng fǎ |
| signature | 方法签名 | fāng fǎ qiān míng |
| parameter | 形参 | xíng cān |
| argument | 实参 | shí cān |
| overloading | 重载 | zhòng zài |
A method's name tag
- A method 方法 is a named block of code you can call to do a job.
- Its signature 方法签名 is the part that identifies it: the name plus the parameter list.
- Example signature:
max(int a, int b)— namemax, twointparameters. - The signature is how Java knows which method you mean when you call one.
Parameters and arguments
- A parameter 形参 is a variable in the method's definition:
int ainmax(int a, int b). - An argument 实参 is the actual value you pass when calling:
max(5, 9)passes5and9. - Arguments are matched to parameters by position, left to right.
- Inside the method, the parameters hold copies of the arguments.
The return type
- A method's return type says what kind of value it hands back.
public int max(int a, int b)returns anint; avoidmethod returns nothing.- Use
return value;to send a result back to the caller. - The return type is part of the header but not part of the signature.
Overloading: same name, different signature
- Java allows overloading 重载: several methods with the same name but different parameter lists.
print(int x)andprint(String s)are distinct — the argument types tell them apart.- The compiler picks the version whose signature matches your arguments.
- Overloading only works when the signatures differ (return type alone is not enough).
The signature is name + parameter list — the return type is NOT part of it. That's why you can't overload two methods that differ only by return type. Parameters live in the definition; arguments are the values you pass, matched by position. Passing the wrong number or type of arguments is a compile error.
Calling max:
- Definition:
public int max(int a, int b) { return a > b ? a : b; } - Call:
int m = max(5, 9);→ argument5→ parametera,9→b. - The method returns
9, stored inm.
A method signature is its name plus parameter list (the return type is not part of it). Parameters are the definition's variables; arguments are the values passed at a call, matched by position. Overloading allows the same name with different parameter lists, distinguished by the arguments.
A method call returns a value
Arguments 5 and 9 bind to parameters a and b; the method returns 9.
A method's signature consists of its...
Signature = name + parameters; the return type is not part of it.
In max(5, 9), the values 5 and 9 are the...
Arguments are the values passed; parameters live in the definition.
You can overload two methods that differ only in their return type.
The return type isn't part of the signature, so that's not allowed.
Having several methods with the same name but different parameter lists is called...
Overloading = same name, different parameter lists.
Arguments are matched to parameters by their ___ (one word), left to right.
Positional matching: first argument → first parameter.