什么是方法?
基本介绍
- 在其他语言中也叫函数
- System.out.println();类名.对象.方法;
- Java方法是语句的集合,它们在一起执行一个功能
- 方法是解决一类问题的步骤的有序集合
- 方法包含于类或者方法中
- 方法在程序中被创建,在其他地方被引用
- 设计方法原理:方法的原意是功能块,它是实现某一功能的语句块的集合。
[En]
Principle of design method: the original meaning of method is function block, which is a collection of statement blocks to realize a certain function.
(在设计方法时,我们最好保持方法的原子性,即一个方法只完成一个函数,这有利于我们以后的扩展)
[En]
(When designing methods, we'd better keep the atomicity of methods, that is, one method only completes one function, which is conducive to our later expansion)*
- 方法的命名规则:大驼峰(和类名一样)
运用实例
```
public class What {
public static void main(String[] args) {
int sum=add(1,2);