| English | 意味 |
|---|---|
| method/ˈmeθəd/ | メソッド |
| signature/ˈsɪɡnɪtʃə/ | シグネチャ |
| parameter/pəˈræmɪtə/ | 引数(形式) |
| argument/ˈɑːɡjuːmənt/ | 実引数 |
| overloading/ˌəʊvəˈləʊdɪŋ/ | オーバーロード |
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.
メソッド呼び出しは値を返す
引数5と9はパラメータaとbにバインドされ、メソッドは9を返す。
メソッドのシグネチャはそれらの...で構成される
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
シグネチャ = 名前 + パラメータ;返り値型は含まれない。
max(5, 9)において、値5と9は...
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
引数は渡される値であり、パラメータは定義内に存在する。
返り値型のみが異なる2つのメソッドをオーバーロードできる。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
返り値型はシグネチャの一部ではないため、それは許可されていない。
同じ名前だが異なるパラメータリストを持つ複数のメソッドがあることは...と呼ばれる
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
オーバーロード = 同じ名前、異なるパラメータリスト。
引数はパラメータに___(単語一つ)によって左から右へマッチングされる。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
位置に基づくマッチング:最初の引数 → 最初のパラメータ。