Methods
- Defining & Calling Methods
- Inputs & Output of A Method
e.g.
1 submitOrder(…){
calculatePrice(…);
}
2 cacalculatePrice(…){_}
1 to 2 zero or more input parameters(输入参数)
2 to 1 zero or one return value(返回值) - Defining a method
e.g.
private int calculatePrice(int quantity){ }
“private” : Access modifer(访问修饰符) Who has access to this method? Private or Public ?
“int”: Return data type(输出返回数据类型)
“calculatePrice”: Method name(用动词开头)
“int”: Parameter data type(输入参数类型)
“quantity”: Parameter variable name - Input Parameters
The inputs passed to a method can be called arguments.(实参)
NOTE:Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration’s parameters in type and order. - Return Values
a.return price;
b.if you don’t need a return value, build a void return value type, like this :
private void price(int quantity){
}
c.codes are unreachable after return.
d.specify return data type.
e.remenber always add comments.
f.numbers should not be in quotes
近期评论