Method
A collection of statements that are grouped together to perform an operation.
Define a mehod
^
Invoke when need
^
用Math 时用static method
不是static 就必须被invoked from an using obj
Signature
A combination of the method name and the parameter list.
Syntax
methodHeader modifier returnType methodName(parameter(s)){
body statement
(return statement)
}
example
public static int max(int num1, nint num2){
return num1>num2 ? num1 : num2;
}
Parameter
Formal PArmeter: The variables defined in the method header.
Actual Parameter: Refereing the value when a method is invoked.
Return type
- A method may return a value. ( 如果定义为void则不用)
- main() 总是void
- The returnValueType is the data typeof the value the method returns.
Overloading
- A class has multiple methods having same name but different in parameters
- 两个影响overload的条件:
- argument的数量
- data type
- 与return type无关: 会导致ambiguity。